diff --git a/src/dashboards/AssignmentCreator.tsx b/src/dashboards/AssignmentCreator.tsx index fd721ab4..dcd94a9d 100644 --- a/src/dashboards/AssignmentCreator.tsx +++ b/src/dashboards/AssignmentCreator.tsx @@ -19,6 +19,7 @@ import {toast} from "react-toastify"; import {uuidv4} from "@firebase/util"; import {Assignment} from "@/interfaces/results"; import Checkbox from "@/components/Low/Checkbox"; +import {Variant} from "@/interfaces/exam"; interface Props { isCreating: boolean; @@ -38,6 +39,7 @@ export default function AssignmentCreator({isCreating, assignment, assigner, gro const [endDate, setEndDate] = useState( assignment ? moment(assignment.endDate).toDate() : moment().hours(23).minutes(59).add(8, "day").toDate(), ); + const [variant, setVariant] = useState("full"); // creates a new exam for each assignee or just one exam for all assignees const [generateMultiple, setGenerateMultiple] = useState(false); @@ -60,6 +62,7 @@ export default function AssignmentCreator({isCreating, assignment, assigner, gro endDate, selectedModules, generateMultiple, + variant, }) .then(() => { toast.success(`The assignment "${name}" has been ${assignment ? "updated" : "created"} successfully!`); @@ -279,7 +282,10 @@ export default function AssignmentCreator({isCreating, assignment, assigner, gro ))} -
+
+ setVariant((prev) => (prev === "full" ? "partial" : "full"))}> + Full length exams + setGenerateMultiple((d) => !d)}> Generate different exams diff --git a/src/interfaces/exam.ts b/src/interfaces/exam.ts index b8e12632..2f3e2128 100644 --- a/src/interfaces/exam.ts +++ b/src/interfaces/exam.ts @@ -1,7 +1,7 @@ import {Module} from "."; export type Exam = ReadingExam | ListeningExam | WritingExam | SpeakingExam | LevelExam; -export type Variant = "full" | "diagnostic" | "partial"; +export type Variant = "full" | "partial"; export interface ReadingExam { parts: ReadingPart[]; diff --git a/src/pages/api/assignments/index.ts b/src/pages/api/assignments/index.ts index a34228d1..5d454fe1 100644 --- a/src/pages/api/assignments/index.ts +++ b/src/pages/api/assignments/index.ts @@ -7,7 +7,7 @@ import {sessionOptions} from "@/lib/session"; import {uuidv4} from "@firebase/util"; import {Module} from "@/interfaces"; import {getExams} from "@/utils/exams.be"; -import {Exam} from "@/interfaces/exam"; +import {Exam, Variant} from "@/interfaces/exam"; import {capitalize, flatten} from "lodash"; import {User} from "@/interfaces/user"; import moment from "moment"; @@ -52,13 +52,18 @@ function getRandomIndex(arr: any[]): number { return randomIndex; } -const generateExams = async (generateMultiple: Boolean, selectedModules: Module[], assignees: string[]): Promise => { +const generateExams = async ( + generateMultiple: Boolean, + selectedModules: Module[], + assignees: string[], + variant?: Variant, +): Promise => { if (generateMultiple) { // for optimization purposes, it would be better to create a new endpoint that returned the answers for all users at once const allExams = await assignees.map(async (assignee) => { const selectedModulePromises = await selectedModules.map(async (module: Module) => { try { - const exams: Exam[] = await getExams(db, module, "true", assignee); + const exams: Exam[] = await getExams(db, module, "true", assignee, variant); const exam = exams[getRandomIndex(exams)]; if (exam) { @@ -101,6 +106,7 @@ async function POST(req: NextApiRequest, res: NextApiResponse) { // Generate multiple true would generate an unique exam for each user // false would generate the same exam for all users generateMultiple = false, + variant, ...body } = req.body as { selectedModules: Module[]; @@ -109,9 +115,10 @@ async function POST(req: NextApiRequest, res: NextApiResponse) { name: string; startDate: string; endDate: string; + variant?: Variant; }; - const exams: ExamWithUser[] = await generateExams(generateMultiple, selectedModules, assignees); + const exams: ExamWithUser[] = await generateExams(generateMultiple, selectedModules, assignees, variant); if (exams.length === 0) { res.status(400).json({ok: false, error: "No exams found for the selected modules"}); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 79322a97..d603cb17 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -176,7 +176,7 @@ export default function Home({envVariables}: {envVariables: {[key: string]: stri {user.type === "corporate" && } {user.type === "agent" && } {user.type === "admin" && } - {user.type === "developer" && } + {user.type === "developer" && } )}