diff --git a/controllers/contentControllers/exercise.js b/controllers/contentControllers/exercise.js index f3230f5..a720b8c 100644 --- a/controllers/contentControllers/exercise.js +++ b/controllers/contentControllers/exercise.js @@ -186,7 +186,17 @@ export const getExerciseByLevelId = async (req, res) => { try { const { idLevel } = req.params; - const levelExists = await models.Level.findByPk(idLevel); + const levelExists = await models.Level.findByPk(idLevel, { + include: [ + { + model: models.Topic, + as: "levelTopic", + attributes: ["NAME_TOPIC"], + }, + ], + attributes: ["NAME_LEVEL"], + }); + if (!levelExists) { return response(404, null, "Level not found", res); } @@ -254,87 +264,19 @@ export const getExerciseByLevelId = async (req, res) => { return exerciseData; }); - response(200, formattedExercises, "Success", res); + const responsePayload = { + NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC, + NAME_LEVEL: levelExists.NAME_LEVEL, + EXERCISES: formattedExercises, + }; + + response(200, responsePayload, "Success", res); } catch (error) { console.log(error); res.status(500).json({ message: "Internal Server Error" }); } }; -// export const deleteExerciseById = async (req, res) => { -// const { id } = req.params; -// const transaction = await models.db.transaction(); - -// try { -// const exercise = await models.Exercise.findByPk(id, { -// include: [ -// { -// model: models.MultipleChoices, -// as: "multipleChoices", -// }, -// { -// model: models.MatchingPairs, -// as: "matchingPairs", -// }, -// { -// model: models.TrueFalse, -// as: "trueFalse", -// }, -// ], -// }); - -// if (!exercise) { -// await transaction.rollback(); -// return response(404, null, "Exercise not found", res); -// } - -// if (exercise.AUDIO) { -// const audioPath = path.join( -// "public/uploads/exercise/audio", -// exercise.AUDIO -// ); -// if (fs.existsSync(audioPath)) fs.unlinkSync(audioPath); -// } - -// if (exercise.IMAGE) { -// const imagePath = path.join( -// "public/uploads/exercise/image", -// exercise.IMAGE -// ); -// if (fs.existsSync(imagePath)) fs.unlinkSync(imagePath); -// } - -// const questionType = exercise.QUESTION_TYPE; - -// if (questionType === "MCQ") { -// await models.MultipleChoices.destroy({ -// where: { ID_ADMIN_EXERCISE: id }, -// transaction, -// }); -// } else if (questionType === "MPQ") { -// await models.MatchingPairs.destroy({ -// where: { ID_ADMIN_EXERCISE: id }, -// transaction, -// }); -// } else if (questionType === "TFQ") { -// await models.TrueFalse.destroy({ -// where: { ID_ADMIN_EXERCISE: id }, -// transaction, -// }); -// } - -// await exercise.destroy({ transaction }); - -// await transaction.commit(); - -// response(200, null, "Exercise and related data deleted successfully", res); -// } catch (error) { -// console.log(error); -// await transaction.rollback(); -// response(500, null, "Internal Server Error", res); -// } -// }; - export const deleteExerciseById = async (req, res) => { const { id } = req.params; const transaction = await models.db.transaction(); diff --git a/controllers/contentControllers/level.js b/controllers/contentControllers/level.js index 39161ad..011af9c 100644 --- a/controllers/contentControllers/level.js +++ b/controllers/contentControllers/level.js @@ -214,6 +214,8 @@ export const getLevelsByTopicId = async (req, res) => { ID_STUDENT_LEARNING: lastCompletedLearning.ID_STUDENT_LEARNING, ID_LEVEL: lastCompletedLearning.level.ID_LEVEL, NAME_LEVEL: lastCompletedLearning.level.NAME_LEVEL, + SCORE: lastCompletedLearning.SCORE, + NEXT_LEARNING: lastCompletedLearning.NEXT_LEARNING, FINISHED_AT: lastCompletedLearning.STUDENT_FINISH, } : null,