mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 13:51:13 -05:00
Implement plan
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Json } from '@/integrations/supabase/types';
|
||||
import { ImageAssignments } from '@/components/upload/EntityMultiImageUploader';
|
||||
import { uploadPendingImages } from './imageUploadHelper';
|
||||
import type { ProcessedImage } from './supabaseHelpers';
|
||||
import { extractChangedFields } from './submissionChangeDetection';
|
||||
|
||||
/**
|
||||
* ═══════════════════════════════════════════════════════════════════
|
||||
@@ -301,8 +302,8 @@ export async function submitParkUpdate(
|
||||
item_type: 'park',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
park_id: parkId,
|
||||
...extractChangedFields(data, existingPark),
|
||||
park_id: parkId, // Always include for relational integrity
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingPark)),
|
||||
@@ -464,8 +465,8 @@ export async function submitRideUpdate(
|
||||
item_type: 'ride',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
ride_id: rideId,
|
||||
...extractChangedFields(data, existingRide),
|
||||
ride_id: rideId, // Always include for relational integrity
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingRide)),
|
||||
@@ -610,8 +611,8 @@ export async function submitRideModelUpdate(
|
||||
item_type: 'ride_model',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
ride_model_id: rideModelId,
|
||||
...extractChangedFields(data, existingModel),
|
||||
ride_model_id: rideModelId, // Always include for relational integrity
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingModel)),
|
||||
@@ -722,9 +723,9 @@ export async function submitManufacturerUpdate(
|
||||
item_type: 'manufacturer',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'manufacturer',
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'manufacturer', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
@@ -830,9 +831,9 @@ export async function submitDesignerUpdate(
|
||||
item_type: 'designer',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'designer',
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'designer', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
@@ -938,9 +939,9 @@ export async function submitOperatorUpdate(
|
||||
item_type: 'operator',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'operator',
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'operator', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
@@ -1046,9 +1047,9 @@ export async function submitPropertyOwnerUpdate(
|
||||
item_type: 'property_owner',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...data,
|
||||
company_id: companyId,
|
||||
company_type: 'property_owner',
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'property_owner', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
@@ -1167,21 +1168,14 @@ export async function submitTimelineEventUpdate(
|
||||
throw new Error('Failed to fetch original timeline event');
|
||||
}
|
||||
|
||||
// Prepare item data
|
||||
// Extract only changed fields from form data
|
||||
const changedFields = extractChangedFields(data, originalEvent as any);
|
||||
|
||||
const itemData: Record<string, any> = {
|
||||
...changedFields,
|
||||
// Always include entity reference (for FK integrity)
|
||||
entity_type: originalEvent.entity_type,
|
||||
entity_id: originalEvent.entity_id,
|
||||
event_type: data.event_type,
|
||||
event_date: data.event_date.toISOString().split('T')[0],
|
||||
event_date_precision: data.event_date_precision,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
from_value: data.from_value,
|
||||
to_value: data.to_value,
|
||||
from_entity_id: data.from_entity_id,
|
||||
to_entity_id: data.to_entity_id,
|
||||
from_location_id: data.from_location_id,
|
||||
to_location_id: data.to_location_id,
|
||||
is_public: true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user