From 328a77a0a8efff9ff6aae7b59559b7c3760242dc Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Thu, 6 Nov 2025 04:50:48 +0000 Subject: [PATCH] Fix: Normalize park_type in approval function --- .../process-selective-approval/index.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/supabase/functions/process-selective-approval/index.ts b/supabase/functions/process-selective-approval/index.ts index 10e4b70e..4d6ab8f0 100644 --- a/supabase/functions/process-selective-approval/index.ts +++ b/supabase/functions/process-selective-approval/index.ts @@ -1519,6 +1519,27 @@ function normalizeStatusValue(data: any): any { return data; } +function normalizeParkTypeValue(data: any): any { + if (data.park_type) { + // Map display values to database values + const parkTypeMap: Record = { + // Display names + 'Theme Park': 'theme_park', + 'Amusement Park': 'amusement_park', + 'Water Park': 'water_park', + 'Family Entertainment': 'family_entertainment', + // Already lowercase values (for new submissions) + 'theme_park': 'theme_park', + 'amusement_park': 'amusement_park', + 'water_park': 'water_park', + 'family_entertainment': 'family_entertainment' + }; + + data.park_type = parkTypeMap[data.park_type] || data.park_type; + } + return data; +} + async function createPark(supabase: any, data: any): Promise { const submitterId = data._submitter_id; let uploadedPhotos: any[] = []; @@ -1597,7 +1618,7 @@ async function createPark(supabase: any, data: any): Promise { parkId = data.park_id; delete data.park_id; // Remove ID from update data - const normalizedData = normalizeStatusValue(data); + const normalizedData = normalizeParkTypeValue(normalizeStatusValue(data)); const sanitizedData = sanitizeDateFields(normalizedData); const filteredData = filterDatabaseFields(sanitizedData, PARK_FIELDS); const { error } = await supabase @@ -1608,7 +1629,7 @@ async function createPark(supabase: any, data: any): Promise { if (error) throw new Error(`Failed to update park: ${error.message}`); } else { edgeLogger.info('Creating new park', { action: 'approval_create_park' }); - const normalizedData = normalizeStatusValue(data); + const normalizedData = normalizeParkTypeValue(normalizeStatusValue(data)); const sanitizedData = sanitizeDateFields(normalizedData); const filteredData = filterDatabaseFields(sanitizedData, PARK_FIELDS); const { data: park, error } = await supabase