summaryrefslogtreecommitdiff
path: root/sql/functions/auth.update_user.sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql/functions/auth.update_user.sql')
-rw-r--r--sql/functions/auth.update_user.sql45
1 files changed, 45 insertions, 0 deletions
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;