refactor: get exercise by level id function

This commit is contained in:
elangptra 2024-10-14 15:18:13 +07:00
parent 4ced73bca2
commit f4a3e6d02d
2 changed files with 12 additions and 13 deletions

View File

@ -347,7 +347,7 @@ export const refreshToken = async (req, res) => {
res.cookie("refreshToken", newRefreshToken, { res.cookie("refreshToken", newRefreshToken, {
httpOnly: true, httpOnly: true,
secure: process.env.NODE_ENV === "production", secure: process.env.NODE_ENV === "production",
sameSite: "Strict", // sameSite: "Strict",
maxAge: 7 * 24 * 60 * 60 * 1000 maxAge: 7 * 24 * 60 * 60 * 1000
}); });

View File

@ -308,6 +308,13 @@ export const getExerciseByLevelId = async (req, res) => {
model: models.Topic, model: models.Topic,
as: "levelTopic", as: "levelTopic",
attributes: ["NAME_TOPIC"], attributes: ["NAME_TOPIC"],
include: [
{
model: models.Section,
as: "topicSection",
attributes: ["NAME_SECTION"],
},
],
}, },
], ],
attributes: ["NAME_LEVEL"], attributes: ["NAME_LEVEL"],
@ -320,18 +327,9 @@ export const getExerciseByLevelId = async (req, res) => {
const exercises = await models.Exercise.findAll({ const exercises = await models.Exercise.findAll({
where: { ID_LEVEL: idLevel, IS_DELETED: 0 }, where: { ID_LEVEL: idLevel, IS_DELETED: 0 },
include: [ include: [
{ { model: models.MultipleChoices, as: "multipleChoices" },
model: models.MultipleChoices, { model: models.MatchingPairs, as: "matchingPairs" },
as: "multipleChoices", { model: models.TrueFalse, as: "trueFalse" },
},
{
model: models.MatchingPairs,
as: "matchingPairs",
},
{
model: models.TrueFalse,
as: "trueFalse",
},
], ],
}); });
@ -381,6 +379,7 @@ export const getExerciseByLevelId = async (req, res) => {
}); });
const responsePayload = { const responsePayload = {
NAME_SECTION: levelExists.levelTopic.topicSection.NAME_SECTION,
NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC, NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC,
NAME_LEVEL: levelExists.NAME_LEVEL, NAME_LEVEL: levelExists.NAME_LEVEL,
EXERCISES: formattedExercises, EXERCISES: formattedExercises,