Update controllers

This commit is contained in:
AndrewTrieu
2023-03-09 17:10:23 +02:00
parent e6d68e98d6
commit 4f94f70a9b
5 changed files with 188 additions and 44 deletions

View File

@@ -17,15 +17,18 @@ const addAnswer = async (questionId, optionText, isCorrect) => {
const deleteAnswer = async (questionId, optionId) => {
await sql`DELETE FROM question_answer_options WHERE question_id = ${questionId} AND id = ${optionId}`;
};
const deleteAnswerByOptionId = async (optionId) => {
await sql`DELETE FROM question_answer_options WHERE id = ${optionId}`;
};
const getCorrectOption = async (questionId) => {
const getCorrectOptionIds = async (questionId) => {
const result =
await sql`SELECT * FROM question_answer_options WHERE question_id = ${questionId} AND is_correct = true`;
await sql`SELECT id FROM question_answer_options WHERE question_id = ${questionId} AND is_correct = true`;
return result.rows;
};
const getCorrectOptions = async (questionId) => {
const result =
await sql`SELECT option_text FROM question_answer_options WHERE question_id = ${questionId} AND is_correct = true`;
return result.rows;
};
@@ -38,7 +41,7 @@ export {
getAnswersByQuestionId,
addAnswer,
deleteAnswer,
deleteAnswerByOptionId,
getCorrectOption,
getCorrectOptionIds,
getCorrectOptions,
storeAnswer,
};