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