find_workgroup_by_id return members

fix find_workgroup_members if no members
This commit is contained in:
2020-03-24 23:38:07 +01:00
parent 75af31ab73
commit e85c8a3d55
3 changed files with 9 additions and 5 deletions

View File

@@ -8,10 +8,10 @@ begin
select select
w.*, w.*,
find_citizen_by_id(w.created_by_id) as created_by, find_citizen_by_id(w.created_by_id) as created_by,
find_citizen_by_id(w.owner_id) as owner find_citizen_by_id(w.owner_id) as owner,
find_workgroup_members(w.id) as members
into resource into resource
from workgroup as w from workgroup as w
left join citizen_in_workgroup ciw on w.id = ciw.workgroup_id
where w.id = _id where w.id = _id
and deleted_at is null and deleted_at is null
) as t; ) as t;

View File

@@ -7,10 +7,11 @@ begin
z.*, z.*,
find_user_by_id(z.user_id) as "user" find_user_by_id(z.user_id) as "user"
from citizen_in_workgroup as ciw from citizen_in_workgroup as ciw
join workgroup as w on ciw.workgroup_id = w.id
join citizen z on z.id = ciw.citizen_id join citizen z on z.id = ciw.citizen_id
where ciw.workgroup_id = _id where ciw.workgroup_id = _id and (w.deleted_at is null or w.deleted_at > now())
) as t; ) as t;
resource = coalesce(resource, '[]'::json);
end; end;
$$; $$;

View File

@@ -82,6 +82,9 @@ begin
'Members must contain citizen1'; 'Members must contain citizen1';
assert not members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id2)), assert not members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id2)),
'Members must NOT contain citizen2'; 'Members must NOT contain citizen2';
-- Check if find_workgroup_by_id return members
select find_workgroup_by_id((created_workgroup->>'id')::uuid) into selected_workgroup;
assert json_array_length(selected_workgroup->'members') = 1, 'Workgroup must have members';
rollback; rollback;
raise notice 'workgroup test pass'; raise notice 'workgroup test pass';