Fix: Save submission edits to relational tables

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 21:08:53 +00:00
parent 6c5b5363c0
commit caa6c788df

View File

@@ -1309,6 +1309,88 @@ export async function editSubmissionItem(
if (updateError) throw updateError; if (updateError) throw updateError;
// Update relational table with new data based on item type
if (currentItem.item_type === 'park') {
// For parks, store location in temp_location_data if provided
const updateData: any = { ...newData };
// If location object is provided, store it in temp_location_data
if (newData.location) {
updateData.temp_location_data = {
name: newData.location.name,
city: newData.location.city || null,
state_province: newData.location.state_province || null,
country: newData.location.country,
latitude: newData.location.latitude,
longitude: newData.location.longitude,
timezone: newData.location.timezone || null,
postal_code: newData.location.postal_code || null,
display_name: newData.location.display_name
};
delete updateData.location; // Remove the nested object
}
// Update park_submissions table
const { error: parkUpdateError } = await supabase
.from('park_submissions')
.update(updateData)
.eq('submission_id', currentItem.submission_id);
if (parkUpdateError) throw parkUpdateError;
} else if (currentItem.item_type === 'ride') {
const { error: rideUpdateError } = await supabase
.from('ride_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id);
if (rideUpdateError) throw rideUpdateError;
} else if (currentItem.item_type === 'manufacturer') {
const { error: manufacturerUpdateError } = await supabase
.from('company_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id)
.eq('company_type', 'manufacturer');
if (manufacturerUpdateError) throw manufacturerUpdateError;
} else if (currentItem.item_type === 'designer') {
const { error: designerUpdateError } = await supabase
.from('company_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id)
.eq('company_type', 'designer');
if (designerUpdateError) throw designerUpdateError;
} else if (currentItem.item_type === 'operator') {
const { error: operatorUpdateError } = await supabase
.from('company_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id)
.eq('company_type', 'operator');
if (operatorUpdateError) throw operatorUpdateError;
} else if (currentItem.item_type === 'property_owner') {
const { error: ownerUpdateError } = await supabase
.from('company_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id)
.eq('company_type', 'property_owner');
if (ownerUpdateError) throw ownerUpdateError;
} else if (currentItem.item_type === 'ride_model') {
const { error: modelUpdateError } = await supabase
.from('ride_model_submissions')
.update(newData)
.eq('submission_id', currentItem.submission_id);
if (modelUpdateError) throw modelUpdateError;
}
// Phase 4: Record edit history // Phase 4: Record edit history
const { data: historyData, error: historyError } = await supabase const { data: historyData, error: historyError } = await supabase
.from('item_edit_history') .from('item_edit_history')