mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:31:13 -05:00
Fix seed-test-data edge function
This commit is contained in:
@@ -135,9 +135,23 @@ async function getPendingSubmissionItems(
|
||||
supabase: any,
|
||||
itemType: string
|
||||
): Promise<Array<{ id: string; item_data_id: string }>> {
|
||||
// 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 });
|
||||
|
||||
Reference in New Issue
Block a user