#48 Can view workgroup of citizen

This commit is contained in:
2020-05-12 01:26:22 +02:00
parent 460222bf69
commit 678a2f48d2
5 changed files with 35 additions and 5 deletions

View File

@@ -20,7 +20,9 @@ class Citizen(
override val user: User
) : CitizenFull,
CitizenBasic(id, name, email, birthday, voteAnonymous, followAnonymous, user),
EntityCreatedAt by EntityCreatedAtImp()
EntityCreatedAt by EntityCreatedAtImp() {
var workgroups: List<WorkgroupSimple<CitizenRef>> = emptyList()
}
open class CitizenBasic(
id: UUID = UUID.randomUUID(),

View File

@@ -5,12 +5,14 @@ declare
begin
select to_json(t) into resource
from (
select
select
z.*,
find_user_by_id(z.user_id) as "user"
find_user_by_id(z.user_id) as "user",
array_agg(find_workgroup_by_id_simple(ciw.workgroup_id)) as "workgroups"
from citizen as z
left join citizen_in_workgroup ciw on z.id = ciw.citizen_id
where z.id = _id
group by z.id
) as t;
end;
$$;

View File

@@ -7,9 +7,12 @@ begin
from (
select
z.*,
find_user_by_id(z.user_id) as "user"
find_user_by_id(z.user_id) as "user",
array_agg(find_workgroup_by_id_simple(ciw.workgroup_id)) as "workgroups"
from citizen as z
left join citizen_in_workgroup ciw on z.id = ciw.citizen_id
where z.id = _id
group by z.id
) as t;
end;
$$;

View File

@@ -0,0 +1,20 @@
create or replace function find_workgroup_by_id_simple(in id uuid, out resource json) language plpgsql as
$$
declare
_id alias for id;
begin
select to_json(t)
from (
select
w.*,
json_build_object('id', w.created_by_id) as created_by,
json_build_object('id', w.owner_id) as owner
into resource
from workgroup as w
join citizen_in_workgroup ciw on w.id = ciw.workgroup_id
where w.id = _id
and deleted_at is null
group by w.id
) as t;
end;
$$;

View File

@@ -55,6 +55,9 @@ begin
assert members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id3)),
'Members must contain citizen3';
-- Check if "find_citizen_by_id" retrun workgroups of citizen
assert (select find_citizen_by_id(_citizen_id2)#>>'{workgroups, 0, id}') = (created_workgroup->>'id'), 'find_citizen_by_id must return workgroups';
-- update
select m into members from update_workgroup_members((created_workgroup->>'id')::uuid, json_build_array(
json_build_object('id', _citizen_id2),