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.update_user.sql | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sql/functions/auth.update_user.sql (limited to 'sql/functions/auth.update_user.sql') diff --git a/sql/functions/auth.update_user.sql b/sql/functions/auth.update_user.sql new file mode 100644 index 0000000..312bf2e --- /dev/null +++ b/sql/functions/auth.update_user.sql @@ -0,0 +1,45 @@ +drop function auth.update_user( + p_id bigint, + p_username character varying, + p_first_name character varying, + p_last_name character varying, + p_email character varying, + p_phone character varying +); + +create or replace function auth.update_user ( + p_id bigint, + p_username character varying, + p_first_name character varying, + p_last_name character varying, + p_email character varying, + p_phone character varying +) +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 username = p_username, + first_name = p_first_name, + last_name = p_last_name, + email = p_email, + phone = p_phone + 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