101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
![]() |
import { makeRequest } from "@frontend/kitui";
|
||
|
import { CreateQuestionRequest } from "model/question/create";
|
||
|
import { Question } from "model/question/question";
|
||
|
import { GetQuestionListRequest, GetQuestionListResponse } from "model/question/getList";
|
||
|
import { EditQuestionRequest, EditQuestionResponse } from "model/question/edit";
|
||
|
import { DeleteQuestionRequest, DeleteQuestionResponse } from "model/question/delete";
|
||
|
import { CopyQuestionRequest, CopyQuestionResponse } from "model/question/copy";
|
||
|
|
||
|
|
||
|
const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz";
|
||
|
|
||
|
export function createQuestion(body: CreateQuestionRequest = defaultCreateQuestionBody) {
|
||
|
return makeRequest<CreateQuestionRequest, Question>({
|
||
|
url: `${baseUrl}/question/create`,
|
||
|
body,
|
||
|
method: "POST",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function getQuestionList(body: GetQuestionListRequest = defaultGetQuestionListBody) {
|
||
|
return makeRequest<GetQuestionListRequest, GetQuestionListResponse>({
|
||
|
url: `${baseUrl}/question/getList`,
|
||
|
body,
|
||
|
method: "GET",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function editQuestion(updatedQuestion: Question, signal?: AbortSignal) {
|
||
|
const body: EditQuestionRequest = {
|
||
|
id: updatedQuestion.id,
|
||
|
title: updatedQuestion.title,
|
||
|
desc: updatedQuestion.description,
|
||
|
type: updatedQuestion.type,
|
||
|
required: updatedQuestion.required,
|
||
|
page: updatedQuestion.page,
|
||
|
};
|
||
|
|
||
|
return makeRequest<EditQuestionRequest, EditQuestionResponse>({
|
||
|
url: `${baseUrl}/question/edit`,
|
||
|
body,
|
||
|
method: "PATCH",
|
||
|
signal,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function copyQuestion(copyQuestionBody: CopyQuestionRequest) {
|
||
|
return makeRequest<CopyQuestionRequest, CopyQuestionResponse>({
|
||
|
url: `${baseUrl}/question/copy`,
|
||
|
body: copyQuestionBody,
|
||
|
method: "POST",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function deleteQuestion(id: number) {
|
||
|
return makeRequest<DeleteQuestionRequest, DeleteQuestionResponse>({
|
||
|
url: `${baseUrl}/question/delete`,
|
||
|
body: { id },
|
||
|
method: "DELETE",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export const questionApi = {
|
||
|
create: createQuestion,
|
||
|
getList: getQuestionList,
|
||
|
edit: editQuestion,
|
||
|
copy: copyQuestion,
|
||
|
delete: deleteQuestion,
|
||
|
};
|
||
|
|
||
|
|
||
|
const defaultCreateQuestionBody: CreateQuestionRequest = {
|
||
|
"quiz_id": 0,
|
||
|
"title": "string",
|
||
|
"description": "string",
|
||
|
"type": "string",
|
||
|
"required": true,
|
||
|
"page": 0,
|
||
|
"content": "string",
|
||
|
};
|
||
|
|
||
|
const defaultGetQuestionListBody: GetQuestionListRequest = {
|
||
|
"limit": 0,
|
||
|
"offset": 0,
|
||
|
"from": 0,
|
||
|
"to": 0,
|
||
|
"search": "string",
|
||
|
"type": "string",
|
||
|
"deleted": true,
|
||
|
"required": true,
|
||
|
"quiz_id": 0
|
||
|
};
|
||
|
|
||
|
const defaultEditQuestionBody: EditQuestionRequest = {
|
||
|
"id": 0,
|
||
|
"title": "string",
|
||
|
"desc": "string",
|
||
|
"type": "",
|
||
|
"required": true,
|
||
|
"page": 0
|
||
|
};
|