From b8423f4d05c75094b7b9d09c6f0bb353acc9be1c Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Sat, 25 May 2024 18:03:25 -0600 Subject: initial commit --- sql/functions/auth.user_toggle_active.sql | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 sql/functions/auth.user_toggle_active.sql (limited to 'sql/functions/auth.user_toggle_active.sql') diff --git a/sql/functions/auth.user_toggle_active.sql b/sql/functions/auth.user_toggle_active.sql new file mode 100644 index 0000000..adc1b62 --- /dev/null +++ b/sql/functions/auth.user_toggle_active.sql @@ -0,0 +1,31 @@ +drop function auth.user_toggle_active ( + p_id bigint +); + +create or replace function auth.user_toggle_active ( + p_id bigint +) +returns bigint +as $$ +declare + l_id bigint; +begin + select u.id into l_id + from auth.users u + where u.id = p_id; + + if(l_id is not null) then + update auth.users + set active = not active + where id = p_id; + + select u.id into l_id + from auth.users u + where u.id = p_id; + + return l_id; + else + return null; + end if; +end; +$$ language plpgsql; -- cgit v1.3