add benefit eligibility setting to HR members

This commit is contained in:
Danel Kungla
2025-10-03 15:33:38 +03:00
parent 419bcc11cb
commit 47e8bd873c
10 changed files with 287 additions and 19 deletions

View File

@@ -1,2 +1,56 @@
insert into medreport.role_permissions (role, permission) values
('owner', 'benefit.manage');
('owner', 'benefit.manage');
ALTER TABLE medreport.accounts_memberships
ADD COLUMN is_eligible_for_benefits boolean NOT NULL DEFAULT true;
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,
is_eligible_for_benefits boolean
)
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,
am.is_eligible_for_benefits
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;