mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:31:12 -05:00
Fix: Normalize park_type in approval function
This commit is contained in:
@@ -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<string, string> = {
|
||||
// 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<string> {
|
||||
const submitterId = data._submitter_id;
|
||||
let uploadedPhotos: any[] = [];
|
||||
@@ -1597,7 +1618,7 @@ async function createPark(supabase: any, data: any): Promise<string> {
|
||||
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<string> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user