From 68672985ec73293bc8f8f88a444ce43ed9f10c8c Mon Sep 17 00:00:00 2001 From: Karli Date: Wed, 1 Oct 2025 01:48:01 +0300 Subject: [PATCH] feat(MED-171): show full names for company members in table --- ...51001014022_account_members_full_names.sql | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 supabase/migrations/20251001014022_account_members_full_names.sql diff --git a/supabase/migrations/20251001014022_account_members_full_names.sql b/supabase/migrations/20251001014022_account_members_full_names.sql new file mode 100644 index 0000000..1f50a5d --- /dev/null +++ b/supabase/migrations/20251001014022_account_members_full_names.sql @@ -0,0 +1,48 @@ +DROP FUNCTION IF EXISTS medreport.get_account_members(text); + +CREATE OR REPLACE FUNCTION medreport.get_account_members(account_slug text) + RETURNS TABLE( + id uuid, + user_id uuid, + account_id uuid, + role character varying, + role_hierarchy_level integer, + primary_owner_user_id uuid, + name text, + email character varying, + personal_code text, + picture_url character varying, + created_at timestamp with time zone, + updated_at timestamp with time zone +) + LANGUAGE plpgsql + SET search_path TO '' +AS $function$begin + return QUERY + select + acc.id, + am.user_id, + am.account_id, + am.account_role, + r.hierarchy_level, + a.primary_owner_user_id, + TRIM(CONCAT(acc.name, ' ', acc.last_name)) as name, + acc.email, + acc.personal_code, + acc.picture_url, + am.created_at, + am.updated_at + from + medreport.accounts_memberships am + join medreport.accounts a on a.id = am.account_id + join medreport.accounts acc on acc.id = am.user_id + join medreport.roles r on r.name = am.account_role + where + a.slug = account_slug; + +end;$function$ +; + +grant + execute on function medreport.get_account_members (text) to authenticated, + service_role;