Had some errors on updating groups
This commit is contained in:
@@ -50,11 +50,7 @@ async function del(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
if (
|
if (user.type === "admin" || user.type === "developer" || user.id === group.admin) {
|
||||||
user.type === "admin" ||
|
|
||||||
user.type === "developer" ||
|
|
||||||
user.id === group.admin
|
|
||||||
) {
|
|
||||||
await db.collection("groups").deleteOne({id: id});
|
await db.collection("groups").deleteOne({id: id});
|
||||||
|
|
||||||
res.status(200).json({ok: true});
|
res.status(200).json({ok: true});
|
||||||
@@ -79,27 +75,13 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
if (
|
if (user.type === "admin" || user.type === "developer" || user.id === group.admin) {
|
||||||
user.type === "admin" ||
|
|
||||||
user.type === "developer" ||
|
|
||||||
user.id === group.admin
|
|
||||||
) {
|
|
||||||
if ("participants" in req.body) {
|
if ("participants" in req.body) {
|
||||||
const newParticipants = (req.body.participants as string[]).filter(
|
const newParticipants = (req.body.participants as string[]).filter((x) => !group.participants.includes(x));
|
||||||
(x) => !group.participants.includes(x),
|
await Promise.all(newParticipants.map(async (p) => await updateExpiryDateOnGroup(p, group.admin)));
|
||||||
);
|
|
||||||
await Promise.all(
|
|
||||||
newParticipants.map(
|
|
||||||
async (p) => await updateExpiryDateOnGroup(p, group.admin),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.collection("grading").updateOne(
|
await db.collection("groups").updateOne({id: req.session.user.id}, {$set: {id, ...req.body}}, {upsert: true});
|
||||||
{ id: req.session.user.id },
|
|
||||||
{ $set: {id: id, ...req.body} },
|
|
||||||
{ upsert: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).json({ok: true});
|
res.status(200).json({ok: true});
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user