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

@@ -75,10 +75,10 @@ export async function submitCompanyUpdate(
data: CompanyFormData, data: CompanyFormData,
userId: string 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 const { data: existingCompany, error: fetchError } = await supabase
.from('companies') .from('companies')
.select('company_type') .select('*')
.eq('id', companyId) .eq('id', companyId)
.single(); .single();
@@ -112,7 +112,7 @@ export async function submitCompanyUpdate(
if (submissionError) throw submissionError; 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 const { error: itemError } = await supabase
.from('submission_items') .from('submission_items')
.insert({ .insert({
@@ -129,6 +129,7 @@ export async function submitCompanyUpdate(
headquarters_location: data.headquarters_location, headquarters_location: data.headquarters_location,
images: processedImages as any images: processedImages as any
}, },
original_data: existingCompany,
status: 'pending', status: 'pending',
order_index: 0 order_index: 0
}); });

View File

@@ -170,6 +170,16 @@ export async function submitParkUpdate(
data: ParkFormData, data: ParkFormData,
userId: string 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 // Upload any pending local images first
let processedImages = data.images; let processedImages = data.images;
if (data.images?.uploaded && data.images.uploaded.length > 0) { if (data.images?.uploaded && data.images.uploaded.length > 0) {
@@ -197,7 +207,7 @@ export async function submitParkUpdate(
if (submissionError) throw submissionError; 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 const { error: itemError } = await supabase
.from('submission_items') .from('submission_items')
.insert({ .insert({
@@ -208,6 +218,7 @@ export async function submitParkUpdate(
park_id: parkId, park_id: parkId,
images: processedImages as any images: processedImages as any
}, },
original_data: existingPark,
status: 'pending', status: 'pending',
order_index: 0 order_index: 0
}); });
@@ -271,6 +282,16 @@ export async function submitRideUpdate(
data: RideFormData, data: RideFormData,
userId: string 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 // Upload any pending local images first
let processedImages = data.images; let processedImages = data.images;
if (data.images?.uploaded && data.images.uploaded.length > 0) { if (data.images?.uploaded && data.images.uploaded.length > 0) {
@@ -298,7 +319,7 @@ export async function submitRideUpdate(
if (submissionError) throw submissionError; 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 const { error: itemError } = await supabase
.from('submission_items') .from('submission_items')
.insert({ .insert({
@@ -309,6 +330,7 @@ export async function submitRideUpdate(
ride_id: rideId, ride_id: rideId,
images: processedImages as any images: processedImages as any
}, },
original_data: existingRide,
status: 'pending', status: 'pending',
order_index: 0 order_index: 0
}); });