next-app/app/lib/question.ts
Alex Stan 1c6c5327c3 made the quiz functional
Signed-off-by: Alex Stan <alex.stan.2010@proton.me>

Fixed merge conflicts
2024-06-01 21:41:34 +03:00

44 lines
No EOL
1.1 KiB
TypeScript

import { makeDeleteRequest, makeGetRequest, makePostRequest } from "./api";
export const enum QuizQuestion {
UL,
UR,
DL,
DR
};
export const enum AnswerType {
Unset,
Right,
Wrong
};
export type Question = {
id: number;
category: string | null;
type?: string; // TODO: make a TS type for every question type
text: string;
answer: string | boolean | QuizQuestion;
answered?: AnswerType;
}
export const getQuestion = async (id: number): Promise<Question> => {
return makeGetRequest( `questions/${id}/` );
}
export const getQuestions = async (): Promise<Question[]> => {
return makeGetRequest( `questions/` );
}
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}` );
}