diff --git a/src/pages/api/users/list.ts b/src/pages/api/users/list.ts index d5e8c93d..b6d13ade 100644 --- a/src/pages/api/users/list.ts +++ b/src/pages/api/users/list.ts @@ -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)));