Updated a bit more of the way the codes work

This commit is contained in:
Tiago Ribeiro
2023-10-10 21:17:46 +01:00
parent 0c9a49a9c3
commit 1aa4f0ddfd
9 changed files with 73 additions and 61 deletions

View File

@@ -12,6 +12,26 @@ import {
} from "@/interfaces/exam";
import axios from "axios";
export const getExam = async (module: Module, avoidRepeated: boolean): Promise<Exam | undefined> => {
const examRequest = await axios<Exam[]>(`/api/exam/${module}?avoidRepeated=${avoidRepeated}`);
if (examRequest.status !== 200) {
return undefined;
}
const newExam = examRequest.data;
switch (module) {
case "reading":
return newExam.shift() as ReadingExam;
case "listening":
return newExam.shift() as ListeningExam;
case "writing":
return newExam.shift() as WritingExam;
case "speaking":
return newExam.shift() as SpeakingExam;
}
};
export const getExamById = async (module: Module, id: string): Promise<Exam | undefined> => {
const examRequest = await axios<Exam>(`/api/exam/${module}/${id}`);
if (examRequest.status !== 200) {