diff --git a/supabase/migrations/20250825134421_order_possible_actions.sql b/supabase/migrations/20250825134421_order_possible_actions.sql new file mode 100644 index 0000000..86961b9 --- /dev/null +++ b/supabase/migrations/20250825134421_order_possible_actions.sql @@ -0,0 +1,25 @@ +CREATE OR REPLACE FUNCTION medreport.get_order_possible_actions(p_medusa_order_id text) +RETURNS jsonb +LANGUAGE plpgsql +AS $$ +DECLARE + order_status text; + is_queued boolean; +BEGIN + -- Get the analysis order status + SELECT status INTO order_status + FROM medreport.analysis_orders + WHERE medusa_order_id = p_medusa_order_id; + + -- Check if status is QUEUED + is_queued := (order_status = 'QUEUED'); + + -- Return JSON object with actions and their allowed status + RETURN jsonb_build_object( + 'retry_dispatch', is_queued, + 'mark_as_not_received_by_synlab', is_queued + ); +END; +$$; + +grant execute on function medreport.get_order_possible_actions(text) to service_role;