2024-06-01 15:47:53 +03:00
|
|
|
import { makeDeleteRequest, makeGetRequest, makePostRequest } from "./api";
|
|
|
|
|
|
|
|
export const enum QuizQuestion {
|
|
|
|
UL,
|
|
|
|
UR,
|
|
|
|
DL,
|
|
|
|
DR
|
|
|
|
};
|
|
|
|
|
2024-06-01 21:36:06 +03:00
|
|
|
export const enum AnswerType {
|
|
|
|
Unset,
|
|
|
|
Right,
|
|
|
|
Wrong
|
|
|
|
};
|
|
|
|
|
2024-06-01 15:47:53 +03:00
|
|
|
export type Question = {
|
|
|
|
id: number;
|
|
|
|
category: string | null;
|
2024-06-01 21:36:06 +03:00
|
|
|
type?: string; // TODO: make a TS type for every question type
|
2024-06-01 15:47:53 +03:00
|
|
|
text: string;
|
|
|
|
answer: string | boolean | QuizQuestion;
|
2024-06-01 21:36:06 +03:00
|
|
|
answered?: AnswerType;
|
2024-06-01 15:47:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getQuestion = async (id: number): Promise<Question> => {
|
|
|
|
return makeGetRequest( `questions/${id}/` );
|
|
|
|
}
|
|
|
|
|
2024-06-01 21:36:06 +03:00
|
|
|
export const getQuestions = async (): Promise<Question[]> => {
|
|
|
|
return makeGetRequest( `questions/` );
|
|
|
|
}
|
|
|
|
|
2024-06-01 15:47:53 +03:00
|
|
|
export const addQuestion = async (question: Question): Promise<Question> => {
|
|
|
|
console.log( `adding question ${JSON.stringify( question)}` );
|
|
|
|
return makePostRequest( `questions`, question );
|
|
|
|
}
|
|
|
|
|
|
|
|
export const editQuestion = async (question: Question): Promise<Question> => {
|
|
|
|
return makePostRequest( `questions/${question.id}`, question );
|
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteQuestion = async (id: number): Promise<Question> => {
|
|
|
|
return makeDeleteRequest( `questions/${id}` );
|
|
|
|
}
|