summaryrefslogtreecommitdiff
path: root/sql/functions/auth.update_user.sql
blob: 312bf2e8754e84205197e9bb2762cec2337ddd85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;