Updated it so it also appears to teachers

This commit is contained in:
Tiago Ribeiro
2024-09-06 10:10:50 +01:00
parent 08ed8fcb32
commit 271ca7069e

View File

@@ -25,6 +25,13 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!req.session.user) return res.status(200).json(users);
if (req.session.user.type === "admin" || req.session.user.type === "developer") return res.status(200).json(users);
if (req.session.user.type === "teacher") {
const adminGroups = await getGroupsForUser(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)]);
return res.status(200).json(users.filter((x) => participants.includes(x.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)));