mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 02:11:14 -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;
|
const itemType = dep.type === 'company' ? dep.companyType : dep.type;
|
||||||
tempIdMap.set(dep.tempId, orderIndex);
|
tempIdMap.set(dep.tempId, orderIndex);
|
||||||
|
|
||||||
|
// ✅ FIXED: Don't use extractChangedFields for CREATE - include ALL data
|
||||||
|
const { images, ...dataWithoutImages } = dep.data;
|
||||||
const itemData: any = {
|
const itemData: any = {
|
||||||
...extractChangedFields(dep.data, {}),
|
...dataWithoutImages,
|
||||||
images: dep.data.images as unknown as Json
|
images: images as unknown as Json
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add company_type for company entities
|
// Add company_type for company entities
|
||||||
@@ -280,9 +282,11 @@ async function submitCompositeCreation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add primary entity last
|
// Add primary entity last
|
||||||
|
// ✅ FIXED: Don't use extractChangedFields for CREATE - include ALL data
|
||||||
|
const { images: primaryImages, ...primaryDataWithoutImages } = uploadedPrimary.data;
|
||||||
const primaryData: any = {
|
const primaryData: any = {
|
||||||
...extractChangedFields(uploadedPrimary.data, {}),
|
...primaryDataWithoutImages,
|
||||||
images: uploadedPrimary.data.images as unknown as Json
|
images: primaryImages as unknown as Json
|
||||||
};
|
};
|
||||||
|
|
||||||
// Map temporary IDs to order indices for foreign keys
|
// Map temporary IDs to order indices for foreign keys
|
||||||
@@ -461,8 +465,13 @@ export async function submitParkCreation(
|
|||||||
|
|
||||||
if (submissionError) throw submissionError;
|
if (submissionError) throw submissionError;
|
||||||
|
|
||||||
// Extract images for assignment
|
// Get image URLs/IDs from processed images using assignments
|
||||||
const changedFields = extractChangedFields(data, {});
|
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
|
// Insert into relational park_submissions table
|
||||||
const { data: parkSubmission, error: parkSubmissionError } = await supabase
|
const { data: parkSubmission, error: parkSubmissionError } = await supabase
|
||||||
@@ -482,10 +491,10 @@ export async function submitParkCreation(
|
|||||||
operator_id: data.operator_id || null,
|
operator_id: data.operator_id || null,
|
||||||
property_owner_id: data.property_owner_id || null,
|
property_owner_id: data.property_owner_id || null,
|
||||||
location_id: data.location_id || null,
|
location_id: data.location_id || null,
|
||||||
banner_image_url: changedFields.banner_image_url as string || null,
|
banner_image_url: bannerImage?.url || data.banner_image_url || null,
|
||||||
banner_image_id: changedFields.banner_image_id as string || null,
|
banner_image_id: bannerImage?.cloudflare_id || data.banner_image_id || null,
|
||||||
card_image_url: changedFields.card_image_url as string || null,
|
card_image_url: cardImage?.url || data.card_image_url || null,
|
||||||
card_image_id: changedFields.card_image_id as string || null
|
card_image_id: cardImage?.cloudflare_id || data.card_image_id || null
|
||||||
} as any)
|
} as any)
|
||||||
.select('id')
|
.select('id')
|
||||||
.single();
|
.single();
|
||||||
|
|||||||
Reference in New Issue
Block a user