next-app/app/lib/question.ts
Alex Stan 882dd995f9 Added the question and session api and a form component
Signed-off-by: Alex Stan <90788596+Ultra980@users.noreply.github.com>
2024-06-01 15:13:30 +03:00

33 lines
No EOL
926 B
TypeScript

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