Made it so when the timer ends, the module ends
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
import {Module} from "@/interfaces";
|
||||
import {Exam, ReadingExam, ListeningExam, WritingExam, SpeakingExam} from "@/interfaces/exam";
|
||||
import {
|
||||
Exam,
|
||||
ReadingExam,
|
||||
ListeningExam,
|
||||
WritingExam,
|
||||
SpeakingExam,
|
||||
Exercise,
|
||||
UserSolution,
|
||||
FillBlanksExercise,
|
||||
MatchSentencesExercise,
|
||||
} from "@/interfaces/exam";
|
||||
import axios from "axios";
|
||||
|
||||
export const getExamById = async (module: Module, id: string): Promise<Exam | undefined> => {
|
||||
@@ -21,3 +31,37 @@ export const getExamById = async (module: Module, id: string): Promise<Exam | un
|
||||
return newExam as SpeakingExam;
|
||||
}
|
||||
};
|
||||
|
||||
export const defaultUserSolutions = (exercise: Exercise, exam: Exam): UserSolution => {
|
||||
const defaultSettings = {
|
||||
exam: exam.id,
|
||||
exercise: exercise.id,
|
||||
solutions: [],
|
||||
module: exam.module,
|
||||
type: exercise.type,
|
||||
};
|
||||
|
||||
let total = 0;
|
||||
switch (exercise.type) {
|
||||
case "fillBlanks":
|
||||
total = exercise.text.match(/({{\d+}})/g)?.length || 0;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
case "matchSentences":
|
||||
total = exercise.sentences.length;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
case "multipleChoice":
|
||||
total = exercise.questions.length;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
case "writeBlanks":
|
||||
total = exercise.text.match(/({{\d+}})/g)?.length || 0;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
case "writing":
|
||||
total = 1;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
case "speaking":
|
||||
total = 1;
|
||||
return {...defaultSettings, score: {correct: 0, total, missing: total}};
|
||||
default:
|
||||
return {...defaultSettings, score: {correct: 0, total: 0, missing: 0}};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user