amend last commit

This commit is contained in:
Joao Correia
2025-02-05 19:14:18 +00:00
parent 7fb5e1a62b
commit c3849518fb

View File

@@ -62,18 +62,13 @@ async function POST(req: NextApiRequest, res: NextApiResponse) {
// Check whether the id of the exam matches another exam with different
// owners, throw exception if there is, else allow editing
const ownersSet = new Set(docSnap?.owners || []);
const existingExamOwners = docSnap?.owners ?? [];
const newExamOwners = exam.owners ?? [];
if (docSnap !== null) {
if (docSnap.owners === undefined) {
docSnap.owners = [];
}
if (exam.owners === undefined) {
exam.owners = [];
}
if (docSnap.owners?.length !== exam.owners?.length || !exam.owners?.every((e: string) => ownersSet.has(e))) {
throw new Error("Name already exists");
}
const ownersSet = new Set(existingExamOwners);
if (docSnap !== null && (existingExamOwners.length !== newExamOwners.length || !newExamOwners.every((e: string) => ownersSet.has(e)))) {
throw new Error("Name already exists");
}
await db.collection(module).updateOne(