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