mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
fix: trigger Discord notify on onboarding complete
This commit is contained in:
1 parent
3afb091e90
commit
5a69bbc1a5
1 file changed
+34
@@ -0,0 +1,34 @@
|
|||||||
|
-- Change Discord new_user notification from profile creation to onboarding completion
|
||||||
|
-- This way we only get notified about users who actually complete onboarding
|
||||||
|
|
||||||
|
-- Update the trigger function to include onboarding data
|
||||||
|
CREATE OR REPLACE FUNCTION public.notify_new_user_discord()
|
||||||
|
RETURNS trigger
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
SECURITY DEFINER
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM public.notify_discord_event(
|
||||||
|
'new_user',
|
||||||
|
jsonb_build_object(
|
||||||
|
'user_id', NEW.id,
|
||||||
|
'name', NEW.name,
|
||||||
|
'email', NEW.email,
|
||||||
|
'gender', NEW.gender,
|
||||||
|
'usage_reason', NEW.usage_reason,
|
||||||
|
'created_at', NEW.created_at
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
-- Drop the old INSERT trigger and create an UPDATE trigger on onboarding_completed
|
||||||
|
DROP TRIGGER IF EXISTS on_profile_created_discord ON public.profiles;
|
||||||
|
|
||||||
|
CREATE TRIGGER on_onboarding_completed_discord
|
||||||
|
AFTER UPDATE OF onboarding_completed ON public.profiles
|
||||||
|
FOR EACH ROW
|
||||||
|
WHEN (OLD.onboarding_completed IS DISTINCT FROM NEW.onboarding_completed AND NEW.onboarding_completed = true)
|
||||||
|
EXECUTE FUNCTION public.notify_new_user_discord();
|
||||||
Reference in new issue
Block a user