refactor: get student answer function
This commit is contained in:
parent
21bcad6f79
commit
ad2c9e74f4
|
|
@ -105,6 +105,25 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
|||
|
||||
const stdLearning = await models.StdLearning.findByPk(id, {
|
||||
include: [
|
||||
{
|
||||
model: models.Level,
|
||||
as: "level",
|
||||
attributes: ["ID_LEVEL", "NAME_LEVEL"],
|
||||
include: [
|
||||
{
|
||||
model: models.Topic,
|
||||
as: "levelTopic",
|
||||
attributes: ["ID_TOPIC", "NAME_TOPIC"],
|
||||
include: [
|
||||
{
|
||||
model: models.Section,
|
||||
as: "topicSection",
|
||||
attributes: ["ID_SECTION", "NAME_SECTION"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
model: models.StdExercise,
|
||||
as: "stdExercises",
|
||||
|
|
@ -159,13 +178,15 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
|||
|
||||
const stdLearningData = stdLearning.toJSON();
|
||||
|
||||
const { NAME_SECTION } = stdLearningData.level.levelTopic.topicSection;
|
||||
const { NAME_TOPIC } = stdLearningData.level.levelTopic;
|
||||
const { NAME_LEVEL } = stdLearningData.level;
|
||||
|
||||
const sortedExercises = stdLearningData.stdExercises.sort((a, b) => {
|
||||
const titleA = a.stdExerciseExercises.TITLE.toUpperCase();
|
||||
const titleB = b.stdExerciseExercises.TITLE.toUpperCase();
|
||||
|
||||
if (titleA < titleB) return -1;
|
||||
if (titleA > titleB) return 1;
|
||||
return 0;
|
||||
return titleA.localeCompare(titleB);
|
||||
});
|
||||
|
||||
const mappedExercises = sortedExercises.map((exercise) => {
|
||||
|
|
@ -200,7 +221,13 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
|||
return response(
|
||||
200,
|
||||
{
|
||||
...stdLearningData,
|
||||
ID_STUDENT_LEARNING: stdLearningData.ID_STUDENT_LEARNING,
|
||||
ID_LEVEL: stdLearningData.ID_LEVEL,
|
||||
NAME_SECTION,
|
||||
NAME_TOPIC,
|
||||
NAME_LEVEL,
|
||||
SCORE: stdLearningData.SCORE,
|
||||
IS_PASS: stdLearningData.IS_PASS,
|
||||
stdExercises: mappedExercises,
|
||||
},
|
||||
"Student learning exercises retrieved successfully",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user