Finish code base
This commit is contained in:
@@ -29,13 +29,18 @@ const getRandQuestion = async ({ response }) => {
|
||||
|
||||
const checkRandQuestion = async ({ request, response }) => {
|
||||
const body = await request.body();
|
||||
const questionId = body.value.questionId;
|
||||
const optionId = body.value.optionId;
|
||||
const correctOptionIds = await answerService.getCorrectOptionIds(questionId);
|
||||
const correctOptionIdsArray = correctOptionIds.map((option) => {
|
||||
return option.id;
|
||||
});
|
||||
const correct = correctOptionIdsArray.includes(optionId);
|
||||
const data = await body.value;
|
||||
console.log(data);
|
||||
const questionId = data.questionId;
|
||||
const optionId = data.optionId;
|
||||
console.log(questionId);
|
||||
console.log(optionId);
|
||||
const correctOptionIds = (
|
||||
await answerService.getCorrectOptionIds(questionId)
|
||||
).map((obj) => obj.id);
|
||||
console.log(correctOptionIds);
|
||||
const correct = correctOptionIds.includes(Number(optionId));
|
||||
console.log(correct);
|
||||
response.body = { correct: correct };
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ const deleteAnswer = async ({ params, response }) => {
|
||||
const topicId = params.tId;
|
||||
const questionId = params.qId;
|
||||
const optionId = params.oId;
|
||||
await answerService.deleteAnswer(questionId, optionId);
|
||||
await answerService.deleteAnswer(optionId);
|
||||
response.redirect(`/topics/${topicId}/questions/${questionId}`);
|
||||
};
|
||||
|
||||
|
||||
@@ -101,7 +101,6 @@ const storeAnswer = async ({ response, params, state }) => {
|
||||
const correctOptionIds = (
|
||||
await answerService.getCorrectOptionIds(questionId)
|
||||
).map((obj) => obj.id);
|
||||
console.log(correctOptionIds);
|
||||
const correct = correctOptionIds.includes(Number(optionId));
|
||||
await answerService.storeAnswer(userId, questionId, optionId);
|
||||
if (correct) {
|
||||
|
||||
@@ -20,7 +20,7 @@ router.post("/auth/register", authController.register);
|
||||
// topicController routes (topics)
|
||||
router.get("/topics", topicController.listTopics);
|
||||
router.post("/topics", topicController.addTopic);
|
||||
router.get("/topics/:tId/delete", topicController.deleteTopic);
|
||||
router.post("/topics/:tId/delete", topicController.deleteTopic);
|
||||
|
||||
// questionController routes (questions)
|
||||
router.get("/topics/:tId", questionController.listQuestions);
|
||||
@@ -54,6 +54,6 @@ router.post(
|
||||
|
||||
// questionApi routes (API)
|
||||
router.get("/api/questions/random", questionApi.getRandQuestion);
|
||||
router.post("api/questions/answer", questionApi.checkRandQuestion);
|
||||
router.post("/api/questions/answer", questionApi.checkRandQuestion);
|
||||
|
||||
export { router };
|
||||
|
||||
Reference in New Issue
Block a user