Changed the IDs to now be words and allows the assignment to be like chosen

This commit is contained in:
Tiago Ribeiro
2024-07-30 23:18:50 +01:00
parent 02320b9484
commit 0403773b8e
10 changed files with 906 additions and 989 deletions

View File

@@ -102,6 +102,7 @@ const generateExams = async (
async function POST(req: NextApiRequest, res: NextApiResponse) {
const {
examIDs,
selectedModules,
assignees,
// Generate multiple true would generate an unique exam for each user
@@ -111,6 +112,7 @@ async function POST(req: NextApiRequest, res: NextApiResponse) {
instructorGender,
...body
} = req.body as {
examIDs?: {id: string; module: Module}[];
selectedModules: Module[];
assignees: string[];
generateMultiple: Boolean;
@@ -121,7 +123,9 @@ async function POST(req: NextApiRequest, res: NextApiResponse) {
instructorGender?: InstructorGender;
};
const exams: ExamWithUser[] = await generateExams(generateMultiple, selectedModules, assignees, variant, instructorGender);
const exams: ExamWithUser[] = !!examIDs
? examIDs.flatMap((e) => assignees.map((a) => ({...e, assignee: a})))
: await generateExams(generateMultiple, selectedModules, assignees, variant, instructorGender);
if (exams.length === 0) {
res.status(400).json({ok: false, error: "No exams found for the selected modules"});