Updated a bit more of the way the codes work
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user