Fix submission update functions

This commit is contained in:
gpt-engineer-app[bot]
2025-10-03 16:03:07 +00:00
parent 177e86a77a
commit 2426da66cb
2 changed files with 28 additions and 5 deletions

View File

@@ -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
});