mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 17:11:23 -05:00
Fix submission update functions
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user