Made it so when the timer ends, the module ends

This commit is contained in:
Tiago Ribeiro
2023-07-27 13:59:00 +01:00
parent f5c3abb310
commit 77692d270e
16 changed files with 155 additions and 22 deletions

View File

@@ -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}};
}
};