frontAnswerer/lib/utils/sendQuestionAnswer.ts
2025-07-11 18:19:06 +03:00

30 lines
848 B
TypeScript

import { sendAnswer } from "@/api/quizRelase";
import { RealTypedQuizQuestion } from "@/model/questionTypes/shared";
import { OwnVariant, QuestionAnswer, createQuizViewStore } from "@/stores/quizView";
import moment from "moment";
export async function sendQuestionAnswer(
quizId: string,
question: RealTypedQuizQuestion,
questionAnswer: QuestionAnswer | undefined,
ownVariants: OwnVariant[]
) {
if (!questionAnswer) {
return sendAnswer({
questionId: question.id,
body: "",
qid: quizId,
});
}
if (question.type === "text") {
if (moment.isMoment(questionAnswer.answer)) throw new Error("Cannot send Moment in text question");
return sendAnswer({
questionId: question.id,
body: questionAnswer.answer,
qid: quizId,
});
} else throw new Error("Inappropriate question type");
}