2024-06-29 09:32:16 +00:00
|
|
|
import { sendAnswer } from "@/api/quizRelase";
|
|
|
|
import { RealTypedQuizQuestion } from "@/model/questionTypes/shared";
|
2024-09-12 08:43:50 +00:00
|
|
|
import { OwnVariant, QuestionAnswer, createQuizViewStore } from "@/stores/quizView";
|
2024-06-29 09:32:16 +00:00
|
|
|
import moment from "moment";
|
|
|
|
|
2025-05-01 13:23:10 +00:00
|
|
|
export async function sendQuestionAnswer(
|
2024-07-05 17:05:26 +00:00
|
|
|
quizId: string,
|
|
|
|
question: RealTypedQuizQuestion,
|
2024-09-12 08:43:50 +00:00
|
|
|
questionAnswer: QuestionAnswer | undefined,
|
|
|
|
ownVariants: OwnVariant[]
|
2024-07-05 17:05:26 +00:00
|
|
|
) {
|
|
|
|
if (!questionAnswer) {
|
|
|
|
return sendAnswer({
|
|
|
|
questionId: question.id,
|
|
|
|
body: "",
|
|
|
|
qid: quizId,
|
|
|
|
});
|
|
|
|
}
|
2024-06-29 09:32:16 +00:00
|
|
|
|
2025-07-11 15:19:06 +00:00
|
|
|
if (question.type === "text") {
|
|
|
|
if (moment.isMoment(questionAnswer.answer)) throw new Error("Cannot send Moment in text question");
|
2024-10-08 14:27:17 +00:00
|
|
|
|
2025-07-11 15:19:06 +00:00
|
|
|
return sendAnswer({
|
|
|
|
questionId: question.id,
|
|
|
|
body: questionAnswer.answer,
|
|
|
|
qid: quizId,
|
|
|
|
});
|
|
|
|
} else throw new Error("Inappropriate question type");
|
2024-06-29 09:32:16 +00:00
|
|
|
}
|