From 83e20bfd562d7e43efd9a09a56015362721c437d Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Tue, 4 Nov 2025 16:04:04 +0000 Subject: [PATCH] Fix seed-test-data edge function --- supabase/functions/seed-test-data/index.ts | 44 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/supabase/functions/seed-test-data/index.ts b/supabase/functions/seed-test-data/index.ts index ebd0c7ca..8ac0c4e9 100644 --- a/supabase/functions/seed-test-data/index.ts +++ b/supabase/functions/seed-test-data/index.ts @@ -135,9 +135,23 @@ async function getPendingSubmissionItems( supabase: any, itemType: string ): Promise> { + // Determine which FK column to select based on itemType + let fkColumn: string; + if (itemType === 'park') { + fkColumn = 'park_submission_id'; + } else if (itemType === 'ride') { + fkColumn = 'ride_submission_id'; + } else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(itemType)) { + fkColumn = 'company_submission_id'; + } else if (itemType === 'ride_model') { + fkColumn = 'ride_model_submission_id'; + } else { + fkColumn = 'photo_submission_id'; + } + const { data, error } = await supabase .from('submission_items') - .select('id, item_data_id') + .select(`id, ${fkColumn}`) .eq('item_type', itemType) .eq('status', 'pending'); @@ -146,7 +160,11 @@ async function getPendingSubmissionItems( return []; } - return data || []; + // Map the response to maintain backward compatibility + return (data || []).map(item => ({ + id: item.id, + item_data_id: item[fkColumn] + })); } // Get slug from relational submission table @@ -482,16 +500,30 @@ Deno.serve(async (req) => { typeDataId = insertedData?.id; } - // Create submission_item (WITHOUT item_data, using item_data_id) - const { error: itemError } = await supabase.from('submission_items').insert({ + // Create submission_item using type-specific foreign keys + const itemData: any = { id: itemId, submission_id: submissionId, item_type: type, - item_data_id: typeDataId, status: 'pending', order_index: 0, depends_on: options.dependsOn || null - }); + }; + + // Add the appropriate foreign key based on type + if (type === 'park') { + itemData.park_submission_id = typeDataId; + } else if (type === 'ride') { + itemData.ride_submission_id = typeDataId; + } else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(type)) { + itemData.company_submission_id = typeDataId; + } else if (type === 'ride_model') { + itemData.ride_model_submission_id = typeDataId; + } else if (type === 'photo') { + itemData.photo_submission_id = typeDataId; + } + + const { error: itemError } = await supabase.from('submission_items').insert(itemData); if (itemError) { edgeLogger.error('Error inserting submission_item', { type, error: itemError.message });