Removed the user itself

This commit is contained in:
Tiago Ribeiro
2024-09-06 10:12:19 +01:00
parent 271ca7069e
commit b92a4285c9

View File

@@ -30,12 +30,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const belongingGroups = await getGroupsForUser(undefined, req.session.user.id); const belongingGroups = await getGroupsForUser(undefined, req.session.user.id);
const participants = uniq([...adminGroups.flatMap((x) => x.participants), ...belongingGroups.flat().flatMap((x) => x.participants)]); const participants = uniq([...adminGroups.flatMap((x) => x.participants), ...belongingGroups.flat().flatMap((x) => x.participants)]);
return res.status(200).json(users.filter((x) => participants.includes(x.id))); return res.status(200).json(users.filter((x) => participants.includes(x.id) && x.id !== req.session.user!.id));
} }
const adminGroups = await getGroupsForUser(req.session.user.id); const adminGroups = await getGroupsForUser(req.session.user.id);
const groups = await Promise.all(adminGroups.flatMap((x) => x.participants).map(async (x) => await getGroupsForUser(x))); const groups = await Promise.all(adminGroups.flatMap((x) => x.participants).map(async (x) => await getGroupsForUser(x)));
const participants = uniq([...adminGroups.flatMap((x) => x.participants), ...groups.flat().flatMap((x) => x.participants)]); const participants = uniq([...adminGroups.flatMap((x) => x.participants), ...groups.flat().flatMap((x) => x.participants)]);
res.status(200).json(users.filter((x) => participants.includes(x.id))); res.status(200).json(users.filter((x) => participants.includes(x.id) && x.id !== req.session.user!.id));
} }