From f4a3e6d02d41664246f0c28660e6abce753021ad Mon Sep 17 00:00:00 2001 From: elangptra Date: Mon, 14 Oct 2024 15:18:13 +0700 Subject: [PATCH] refactor: get exercise by level id function --- controllers/auth/auth.js | 2 +- controllers/contentControllers/exercise.js | 23 +++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/controllers/auth/auth.js b/controllers/auth/auth.js index 3e737cd..0fe480d 100644 --- a/controllers/auth/auth.js +++ b/controllers/auth/auth.js @@ -347,7 +347,7 @@ export const refreshToken = async (req, res) => { res.cookie("refreshToken", newRefreshToken, { httpOnly: true, secure: process.env.NODE_ENV === "production", - sameSite: "Strict", + // sameSite: "Strict", maxAge: 7 * 24 * 60 * 60 * 1000 }); diff --git a/controllers/contentControllers/exercise.js b/controllers/contentControllers/exercise.js index edc3375..75af06b 100644 --- a/controllers/contentControllers/exercise.js +++ b/controllers/contentControllers/exercise.js @@ -308,6 +308,13 @@ export const getExerciseByLevelId = async (req, res) => { model: models.Topic, as: "levelTopic", attributes: ["NAME_TOPIC"], + include: [ + { + model: models.Section, + as: "topicSection", + attributes: ["NAME_SECTION"], + }, + ], }, ], attributes: ["NAME_LEVEL"], @@ -320,18 +327,9 @@ export const getExerciseByLevelId = async (req, res) => { const exercises = await models.Exercise.findAll({ where: { ID_LEVEL: idLevel, IS_DELETED: 0 }, include: [ - { - model: models.MultipleChoices, - as: "multipleChoices", - }, - { - model: models.MatchingPairs, - as: "matchingPairs", - }, - { - model: models.TrueFalse, - as: "trueFalse", - }, + { model: models.MultipleChoices, as: "multipleChoices" }, + { model: models.MatchingPairs, as: "matchingPairs" }, + { model: models.TrueFalse, as: "trueFalse" }, ], }); @@ -381,6 +379,7 @@ export const getExerciseByLevelId = async (req, res) => { }); const responsePayload = { + NAME_SECTION: levelExists.levelTopic.topicSection.NAME_SECTION, NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC, NAME_LEVEL: levelExists.NAME_LEVEL, EXERCISES: formattedExercises,