From 2426da66cb0744f356e610f264f2fff966aa6d6c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:03:07 +0000 Subject: [PATCH] Fix submission update functions --- src/lib/companyHelpers.ts | 7 ++++--- src/lib/entitySubmissionHelpers.ts | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/lib/companyHelpers.ts b/src/lib/companyHelpers.ts index 50436445..fc12c61c 100644 --- a/src/lib/companyHelpers.ts +++ b/src/lib/companyHelpers.ts @@ -75,10 +75,10 @@ export async function submitCompanyUpdate( data: CompanyFormData, userId: string ) { - // Fetch existing company to get its type + // Fetch existing company data (all fields for original_data) const { data: existingCompany, error: fetchError } = await supabase .from('companies') - .select('company_type') + .select('*') .eq('id', companyId) .single(); @@ -112,7 +112,7 @@ export async function submitCompanyUpdate( if (submissionError) throw submissionError; - // Create the submission item with actual company data + // Create the submission item with actual company data AND original data const { error: itemError } = await supabase .from('submission_items') .insert({ @@ -129,6 +129,7 @@ export async function submitCompanyUpdate( headquarters_location: data.headquarters_location, images: processedImages as any }, + original_data: existingCompany, status: 'pending', order_index: 0 }); diff --git a/src/lib/entitySubmissionHelpers.ts b/src/lib/entitySubmissionHelpers.ts index a3647855..f7328272 100644 --- a/src/lib/entitySubmissionHelpers.ts +++ b/src/lib/entitySubmissionHelpers.ts @@ -170,6 +170,16 @@ export async function submitParkUpdate( data: ParkFormData, userId: string ) { + // Fetch existing park data first + const { data: existingPark, error: fetchError } = await supabase + .from('parks') + .select('*') + .eq('id', parkId) + .single(); + + if (fetchError) throw new Error(`Failed to fetch park: ${fetchError.message}`); + if (!existingPark) throw new Error('Park not found'); + // Upload any pending local images first let processedImages = data.images; if (data.images?.uploaded && data.images.uploaded.length > 0) { @@ -197,7 +207,7 @@ export async function submitParkUpdate( if (submissionError) throw submissionError; - // Create the submission item with actual park data + // Create the submission item with actual park data AND original data const { error: itemError } = await supabase .from('submission_items') .insert({ @@ -208,6 +218,7 @@ export async function submitParkUpdate( park_id: parkId, images: processedImages as any }, + original_data: existingPark, status: 'pending', order_index: 0 }); @@ -271,6 +282,16 @@ export async function submitRideUpdate( data: RideFormData, userId: string ) { + // Fetch existing ride data first + const { data: existingRide, error: fetchError } = await supabase + .from('rides') + .select('*') + .eq('id', rideId) + .single(); + + if (fetchError) throw new Error(`Failed to fetch ride: ${fetchError.message}`); + if (!existingRide) throw new Error('Ride not found'); + // Upload any pending local images first let processedImages = data.images; if (data.images?.uploaded && data.images.uploaded.length > 0) { @@ -298,7 +319,7 @@ export async function submitRideUpdate( if (submissionError) throw submissionError; - // Create the submission item with actual ride data + // Create the submission item with actual ride data AND original data const { error: itemError } = await supabase .from('submission_items') .insert({ @@ -309,6 +330,7 @@ export async function submitRideUpdate( ride_id: rideId, images: processedImages as any }, + original_data: existingRide, status: 'pending', order_index: 0 });