Refactor: Complete JSONB elimination

This commit is contained in:
gpt-engineer-app[bot]
2025-10-21 17:52:13 +00:00
parent 103a12f768
commit d74ece69ee
6 changed files with 854 additions and 23 deletions

View File

@@ -839,6 +839,11 @@ async function createRide(supabase: any, data: any): Promise<string> {
const submitterId = data._submitter_id;
let uploadedPhotos: any[] = [];
// Extract relational data before transformation
const technicalSpecifications = data._technical_specifications || [];
const coasterStatistics = data._coaster_statistics || [];
const nameHistory = data._name_history || [];
// Transform images object if present
if (data.images) {
const { uploaded, banner_assignment, card_assignment } = data.images;
@@ -866,6 +871,9 @@ async function createRide(supabase: any, data: any): Promise<string> {
// Remove internal fields and store park_id before filtering
delete data._submitter_id;
delete data._technical_specifications;
delete data._coaster_statistics;
delete data._name_history;
const parkId = data.park_id;
let rideId: string;
@@ -949,6 +957,71 @@ async function createRide(supabase: any, data: any): Promise<string> {
}
}
// Insert technical specifications
if (technicalSpecifications.length > 0) {
console.log(`Inserting ${technicalSpecifications.length} technical specs for ride ${rideId}`);
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
ride_id: rideId,
spec_name: spec.spec_name,
spec_value: spec.spec_value,
spec_unit: spec.spec_unit || null,
category: spec.category || null,
display_order: spec.display_order || 0
}));
const { error: techSpecError } = await supabase
.from('ride_technical_specifications')
.insert(techSpecsToInsert);
if (techSpecError) {
console.error('Failed to insert technical specifications:', techSpecError);
}
}
// Insert coaster statistics
if (coasterStatistics.length > 0) {
console.log(`Inserting ${coasterStatistics.length} coaster stats for ride ${rideId}`);
const statsToInsert = coasterStatistics.map((stat: any) => ({
ride_id: rideId,
stat_name: stat.stat_name,
stat_value: stat.stat_value,
unit: stat.unit || null,
category: stat.category || null,
description: stat.description || null,
display_order: stat.display_order || 0
}));
const { error: statsError } = await supabase
.from('ride_coaster_stats')
.insert(statsToInsert);
if (statsError) {
console.error('Failed to insert coaster statistics:', statsError);
}
}
// Insert name history
if (nameHistory.length > 0) {
console.log(`Inserting ${nameHistory.length} former names for ride ${rideId}`);
const namesToInsert = nameHistory.map((name: any) => ({
ride_id: rideId,
former_name: name.former_name,
date_changed: name.date_changed || null,
reason: name.reason || null,
from_year: name.from_year || null,
to_year: name.to_year || null,
order_index: name.order_index || 0
}));
const { error: namesError } = await supabase
.from('ride_name_history')
.insert(namesToInsert);
if (namesError) {
console.error('Failed to insert name history:', namesError);
}
}
return rideId;
}
@@ -1010,6 +1083,12 @@ async function createCompany(supabase: any, data: any, companyType: string): Pro
async function createRideModel(supabase: any, data: any): Promise<string> {
let rideModelId: string;
// Extract relational data before transformation
const technicalSpecifications = data._technical_specifications || [];
// Remove internal fields
delete data._technical_specifications;
// Check if this is an edit (has ride_model_id) or a new creation
if (data.ride_model_id) {
console.log(`Updating existing ride model ${data.ride_model_id}`);
@@ -1038,6 +1117,27 @@ async function createRideModel(supabase: any, data: any): Promise<string> {
rideModelId = model.id;
}
// Insert technical specifications
if (technicalSpecifications.length > 0) {
console.log(`Inserting ${technicalSpecifications.length} technical specs for ride model ${rideModelId}`);
const techSpecsToInsert = technicalSpecifications.map((spec: any) => ({
ride_model_id: rideModelId,
spec_name: spec.spec_name,
spec_value: spec.spec_value,
spec_unit: spec.spec_unit || null,
category: spec.category || null,
display_order: spec.display_order || 0
}));
const { error: techSpecError } = await supabase
.from('ride_model_technical_specifications')
.insert(techSpecsToInsert);
if (techSpecError) {
console.error('Failed to insert technical specifications:', techSpecError);
}
}
return rideModelId;
}