mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 09:51:13 -05:00
Fix submission creation process
This commit is contained in:
@@ -249,9 +249,11 @@ async function submitCompositeCreation(
|
||||
const itemType = dep.type === 'company' ? dep.companyType : dep.type;
|
||||
tempIdMap.set(dep.tempId, orderIndex);
|
||||
|
||||
// ✅ FIXED: Don't use extractChangedFields for CREATE - include ALL data
|
||||
const { images, ...dataWithoutImages } = dep.data;
|
||||
const itemData: any = {
|
||||
...extractChangedFields(dep.data, {}),
|
||||
images: dep.data.images as unknown as Json
|
||||
...dataWithoutImages,
|
||||
images: images as unknown as Json
|
||||
};
|
||||
|
||||
// Add company_type for company entities
|
||||
@@ -280,9 +282,11 @@ async function submitCompositeCreation(
|
||||
}
|
||||
|
||||
// Add primary entity last
|
||||
// ✅ FIXED: Don't use extractChangedFields for CREATE - include ALL data
|
||||
const { images: primaryImages, ...primaryDataWithoutImages } = uploadedPrimary.data;
|
||||
const primaryData: any = {
|
||||
...extractChangedFields(uploadedPrimary.data, {}),
|
||||
images: uploadedPrimary.data.images as unknown as Json
|
||||
...primaryDataWithoutImages,
|
||||
images: primaryImages as unknown as Json
|
||||
};
|
||||
|
||||
// Map temporary IDs to order indices for foreign keys
|
||||
@@ -461,8 +465,13 @@ export async function submitParkCreation(
|
||||
|
||||
if (submissionError) throw submissionError;
|
||||
|
||||
// Extract images for assignment
|
||||
const changedFields = extractChangedFields(data, {});
|
||||
// Get image URLs/IDs from processed images using assignments
|
||||
const uploadedImages = processedImages?.uploaded || [];
|
||||
const bannerIndex = processedImages?.banner_assignment;
|
||||
const cardIndex = processedImages?.card_assignment;
|
||||
|
||||
const bannerImage = (bannerIndex !== null && bannerIndex !== undefined) ? uploadedImages[bannerIndex] : null;
|
||||
const cardImage = (cardIndex !== null && cardIndex !== undefined) ? uploadedImages[cardIndex] : null;
|
||||
|
||||
// Insert into relational park_submissions table
|
||||
const { data: parkSubmission, error: parkSubmissionError } = await supabase
|
||||
@@ -482,10 +491,10 @@ export async function submitParkCreation(
|
||||
operator_id: data.operator_id || null,
|
||||
property_owner_id: data.property_owner_id || null,
|
||||
location_id: data.location_id || null,
|
||||
banner_image_url: changedFields.banner_image_url as string || null,
|
||||
banner_image_id: changedFields.banner_image_id as string || null,
|
||||
card_image_url: changedFields.card_image_url as string || null,
|
||||
card_image_id: changedFields.card_image_id as string || null
|
||||
banner_image_url: bannerImage?.url || data.banner_image_url || null,
|
||||
banner_image_id: bannerImage?.cloudflare_id || data.banner_image_id || null,
|
||||
card_image_url: cardImage?.url || data.card_image_url || null,
|
||||
card_image_id: cardImage?.cloudflare_id || data.card_image_id || null
|
||||
} as any)
|
||||
.select('id')
|
||||
.single();
|
||||
|
||||
Reference in New Issue
Block a user