From c8a015a15b4c8502d86d5428d74024e98f525650 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:33:26 +0000 Subject: [PATCH] Fix park type and moderator ID --- src/components/admin/ParkForm.tsx | 20 +++--- ...2_e648df5e-d4ca-4e6a-8f37-d8ebb787daf3.sql | 70 +++++++++++++++++++ 2 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 supabase/migrations/20251106043242_e648df5e-d4ca-4e6a-8f37-d8ebb787daf3.sql diff --git a/src/components/admin/ParkForm.tsx b/src/components/admin/ParkForm.tsx index 728e8d50..3590a5de 100644 --- a/src/components/admin/ParkForm.tsx +++ b/src/components/admin/ParkForm.tsx @@ -93,14 +93,14 @@ interface ParkFormProps { } const parkTypes = [ - 'Theme Park', - 'Amusement Park', - 'Water Park', - 'Family Entertainment Center', - 'Adventure Park', - 'Safari Park', - 'Carnival', - 'Fair' + { value: 'theme_park', label: 'Theme Park' }, + { value: 'amusement_park', label: 'Amusement Park' }, + { value: 'water_park', label: 'Water Park' }, + { value: 'family_entertainment', label: 'Family Entertainment Center' }, + { value: 'adventure_park', label: 'Adventure Park' }, + { value: 'safari_park', label: 'Safari Park' }, + { value: 'carnival', label: 'Carnival' }, + { value: 'fair', label: 'Fair' } ]; const statusOptions = [ @@ -363,8 +363,8 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }: {parkTypes.map((type) => ( - - {type} + + {type.label} ))} diff --git a/supabase/migrations/20251106043242_e648df5e-d4ca-4e6a-8f37-d8ebb787daf3.sql b/supabase/migrations/20251106043242_e648df5e-d4ca-4e6a-8f37-d8ebb787daf3.sql new file mode 100644 index 00000000..e664655c --- /dev/null +++ b/supabase/migrations/20251106043242_e648df5e-d4ca-4e6a-8f37-d8ebb787daf3.sql @@ -0,0 +1,70 @@ +-- Update log_moderation_action to use session variable for moderator_id +-- This allows edge functions using service role to pass the actual moderator ID + +CREATE OR REPLACE FUNCTION public.log_moderation_action( + _submission_id uuid, + _action text, + _previous_status text DEFAULT NULL::text, + _new_status text DEFAULT NULL::text, + _notes text DEFAULT NULL::text, + _metadata jsonb DEFAULT '{}'::jsonb +) +RETURNS uuid +LANGUAGE plpgsql +SECURITY DEFINER +SET search_path TO 'public' +AS $function$ +DECLARE + _log_id UUID; + _metadata_record record; + _moderator_id UUID; +BEGIN + -- Get moderator ID from session variable (set by edge function) or auth.uid() + BEGIN + _moderator_id := COALESCE( + current_setting('app.moderator_id', true)::uuid, + auth.uid() + ); + EXCEPTION WHEN OTHERS THEN + _moderator_id := auth.uid(); + END; + + -- Insert into moderation_audit_log (without metadata JSONB column) + INSERT INTO public.moderation_audit_log ( + submission_id, + moderator_id, + action, + previous_status, + new_status, + notes + ) VALUES ( + _submission_id, + _moderator_id, + _action, + _previous_status, + _new_status, + _notes + ) + RETURNING id INTO _log_id; + + -- Write metadata to relational moderation_audit_metadata table + IF _metadata IS NOT NULL AND jsonb_typeof(_metadata) = 'object' THEN + FOR _metadata_record IN + SELECT key, value::text as text_value + FROM jsonb_each_text(_metadata) + LOOP + INSERT INTO public.moderation_audit_metadata ( + audit_log_id, + metadata_key, + metadata_value + ) VALUES ( + _log_id, + _metadata_record.key, + _metadata_record.text_value + ); + END LOOP; + END IF; + + RETURN _log_id; +END; +$function$; \ No newline at end of file