Updated it so it also appears to teachers
This commit is contained in:
@@ -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) 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 === "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 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)));
|
||||||
|
|||||||
Reference in New Issue
Block a user