Solved a problem related to not showing corporates if they are not in the correct group

This commit is contained in:
Tiago Ribeiro
2024-09-05 12:02:46 +01:00
parent 6ce81b300a
commit b6b5f3a9f1
2 changed files with 38 additions and 3 deletions

View File

@@ -174,6 +174,39 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
}
}
if (maker.type === "corporate") {
await setDoc(doc(db, "codes", code), {creator: maker.id}, {merge: true});
const q = query(
collection(db, "groups"),
where("admin", "==", maker.id),
where("name", "==", type === "student" ? "Students" : "Teachers"),
limit(1),
);
const snapshot = await getDocs(q);
if (!snapshot.empty) {
const doc = snapshot.docs[0];
const participants: string[] = doc.get("participants");
if (!participants.includes(userId)) {
await updateDoc(doc.ref, {
participants: [...participants, userId],
});
}
} else {
const defaultGroup: Group = {
admin: maker.id,
id: v4(),
name: type === "student" ? "Students" : "Teachers",
participants: [userId],
disableEditing: true,
};
await setDoc(doc(db, "groups", defaultGroup.id), defaultGroup);
}
}
if (!!corporateCorporate && corporateCorporate.type === "mastercorporate" && type === "corporate") {
const q = query(collection(db, "groups"), where("admin", "==", corporateCorporate.id), where("name", "==", "corporate"), limit(1));
const snapshot = await getDocs(q);