Created a new system for the Groups that will persist after having entities

This commit is contained in:
Tiago Ribeiro
2024-09-25 16:18:43 +01:00
parent 8c392f8b49
commit dd94228672
18 changed files with 823 additions and 136 deletions

View File

@@ -75,13 +75,20 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
}
const user = req.session.user;
if (user.type === "admin" || user.type === "developer" || user.id === group.admin) {
if ("participants" in req.body) {
if (
user.type === "admin" ||
user.type === "developer" ||
user.type === "mastercorporate" ||
user.type === "corporate" ||
user.id === group.admin
) {
if ("participants" in req.body && req.body.participants.length > 0) {
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("groups").updateOne({id: req.session.user.id}, {$set: {id, ...req.body}}, {upsert: true});
console.log(req.body);
await db.collection("groups").updateOne({id}, {$set: {id, ...req.body}}, {upsert: true});
res.status(200).json({ok: true});
return;