mirror of
https://github.com/renee-png/acmcc.git
synced 2026-06-21 09:50:01 +00:00
Add ACMCC app source, Supabase backend, and project config
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
CREATE OR REPLACE FUNCTION public.auto_owner_update_from_violation()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path TO 'public'
|
||||
AS $function$
|
||||
DECLARE
|
||||
v_title TEXT;
|
||||
v_content TEXT;
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
v_title := 'Violation Issued: ' || COALESCE(NEW.title, NEW.violation_type, 'Untitled');
|
||||
v_content := 'A new violation has been recorded. Category: ' || COALESCE(NEW.category, 'N/A') || '. Status: ' || COALESCE(NEW.status, 'open') || '.';
|
||||
ELSIF TG_OP = 'UPDATE' AND OLD.status IS DISTINCT FROM NEW.status THEN
|
||||
v_title := 'Violation Status Changed: ' || COALESCE(NEW.title, NEW.violation_type, 'Untitled');
|
||||
v_content := 'Status changed from "' || COALESCE(OLD.status, 'unknown') || '" to "' || COALESCE(NEW.status, 'unknown') || '".';
|
||||
ELSE
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
||||
INSERT INTO public.owner_updates (association_id, unit_id, title, content, tags, violation_ids)
|
||||
VALUES (
|
||||
NEW.association_id,
|
||||
NEW.unit_id,
|
||||
v_title,
|
||||
v_content,
|
||||
'[{"name":"Violations","color":"#f59e0b"}]'::jsonb,
|
||||
jsonb_build_array(NEW.id::text)
|
||||
);
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;
|
||||
Reference in New Issue
Block a user