Skip to content

Commit

Permalink
fix (front) [QCMPLUS-40] Update Aswer while creating question
Browse files Browse the repository at this point in the history
Signed-off-by: Teclit <teklitte@gmail.com>
  • Loading branch information
Teclit committed Aug 23, 2024
1 parent 0e70cb1 commit 0ed3880
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,19 @@ const CreateQuestionForm = ({showModal, setShowModal, setSuccessMessage, setErro
quiz: {quizId: selectedQuiz}
};

console.log("Creating question:", dataQuestion);
await createQuestion(dataQuestion.quiz.quizId, dataQuestion);

const response = await getQuestionsByText(dataQuestion.questionText);
const response = await getQuestionsByText(encodeURIComponent(dataQuestion.questionText));
if (response.data.length === 0) {
throw new Error("Question not found after creation.");
}

const questionId = response.data[0].questionId;
console.log("Question ID:", questionId);
const questionId = response.data.questionId;

for (const answer of answers) {
const dataAnswer = {
answerText: answer.answerText,
correct: answer.isCorrect,
question: {questionId: questionId}
};
console.log("Creating answer:", dataAnswer);
await createAnswer(dataAnswer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ const ViewQuestionModal = ({showModal, setShowModal, question}) => {
if (question) {
try {
const response = await getAnswersByQuestionId(question.questionId);
console.log(response.data);
setAnswers(response.data);
} catch (error) {
console.error("Failed to fetch answers", error);
console.error("Failed to fetch answers");
}
}
};
Expand Down

0 comments on commit 0ed3880

Please sign in to comment.