143 lines
3.5 KiB
TypeScript
143 lines
3.5 KiB
TypeScript
![]() |
import { makeRequest } from "@frontend/kitui";
|
||
|
import { CopyQuizRequest, CopyQuizResponse } from "model/quiz/copy";
|
||
|
import { CreateQuizRequest } from "model/quiz/create";
|
||
|
import { DeleteQuizRequest, DeleteQuizResponse } from "model/quiz/delete";
|
||
|
import { EditQuizRequest, EditQuizResponse } from "model/quiz/edit";
|
||
|
import { GetQuizRequest, GetQuizResponse } from "model/quiz/get";
|
||
|
import { GetQuizListRequest, GetQuizListResponse } from "model/quiz/getList";
|
||
|
import { BackendQuiz } from "model/quiz/quiz";
|
||
|
|
||
|
|
||
|
const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz";
|
||
|
|
||
|
function createQuiz(body: CreateQuizRequest = defaultCreateQuizBody) {
|
||
|
return makeRequest<CreateQuizRequest, BackendQuiz>({
|
||
|
url: `${baseUrl}/quiz/create`,
|
||
|
body,
|
||
|
method: "POST",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function getQuizList(body: GetQuizListRequest = defaultGetQuizListBody) {
|
||
|
return makeRequest<GetQuizListRequest, GetQuizListResponse>({
|
||
|
url: `${baseUrl}/quiz/getList`,
|
||
|
body,
|
||
|
method: "GET",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function getQuiz(body: GetQuizRequest = defaultGetQuizBody) {
|
||
|
return makeRequest<GetQuizRequest, GetQuizResponse>({
|
||
|
url: `${baseUrl}/quiz/get`,
|
||
|
body,
|
||
|
method: "GET",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function editQuiz(body: EditQuizRequest = defaultEditQuizBody) {
|
||
|
return makeRequest<EditQuizRequest, EditQuizResponse>({
|
||
|
url: `${baseUrl}/quiz/edit`,
|
||
|
body,
|
||
|
method: "PATCH",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function copyQuiz(id: number) {
|
||
|
return makeRequest<CopyQuizRequest, CopyQuizResponse>({
|
||
|
url: `${baseUrl}/quiz/copy`,
|
||
|
body: { id },
|
||
|
method: "POST",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function deleteQuiz(id: number) {
|
||
|
return makeRequest<DeleteQuizRequest, DeleteQuizResponse>({
|
||
|
url: `${baseUrl}/quiz/delete`,
|
||
|
body: { id },
|
||
|
method: "DELETE",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
function addQuizImages(quizId: number, image: Blob) {
|
||
|
const formData = new FormData();
|
||
|
|
||
|
formData.append("quiz", quizId.toString());
|
||
|
formData.append("image", image);
|
||
|
|
||
|
return makeRequest<FormData, never>({
|
||
|
url: `${baseUrl}/quiz/putImages`,
|
||
|
body: formData,
|
||
|
method: "POST",
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export const quizApi = {
|
||
|
create: createQuiz,
|
||
|
getList: getQuizList,
|
||
|
get: getQuiz,
|
||
|
edit: editQuiz,
|
||
|
copy: copyQuiz,
|
||
|
delete: deleteQuiz,
|
||
|
addImages: addQuizImages,
|
||
|
};
|
||
|
|
||
|
|
||
|
const defaultCreateQuizBody: CreateQuizRequest = {
|
||
|
"fingerprinting": true,
|
||
|
"repeatable": true,
|
||
|
"note_prevented": true,
|
||
|
"mail_notifications": true,
|
||
|
"unique_answers": true,
|
||
|
"name": "string",
|
||
|
"description": "string",
|
||
|
"config": "string",
|
||
|
"status": "string",
|
||
|
"limit": 0,
|
||
|
"due_to": 0,
|
||
|
"time_of_passing": 0,
|
||
|
"pausable": true,
|
||
|
"question_cnt": 0,
|
||
|
"super": true,
|
||
|
"group_id": 0,
|
||
|
};
|
||
|
|
||
|
const defaultEditQuizBody: EditQuizRequest = {
|
||
|
"id": 0,
|
||
|
"fp": true,
|
||
|
"rep": true,
|
||
|
"note_prevented": true,
|
||
|
"mailing": true,
|
||
|
"uniq": true,
|
||
|
"name": "string",
|
||
|
"desc": "string",
|
||
|
"conf": "string",
|
||
|
"status": "string",
|
||
|
"limit": 0,
|
||
|
"due_to": 0,
|
||
|
"time_of_passing": 0,
|
||
|
"pausable": true,
|
||
|
"question_cnt": 0,
|
||
|
"super": true,
|
||
|
"group_id": 0,
|
||
|
};
|
||
|
|
||
|
const defaultGetQuizBody: GetQuizRequest = {
|
||
|
"quiz_id": "string",
|
||
|
"limit": 0,
|
||
|
"page": 0,
|
||
|
"need_config": true,
|
||
|
};
|
||
|
|
||
|
const defaultGetQuizListBody: GetQuizListRequest = {
|
||
|
"limit": 0,
|
||
|
"offset": 0,
|
||
|
"from": 0,
|
||
|
"to": 0,
|
||
|
"search": "string",
|
||
|
"status": "string",
|
||
|
"deleted": true,
|
||
|
"archived": true,
|
||
|
"super": true,
|
||
|
"group_id": 0,
|
||
|
};
|