feat: student activities function and exercise model function
This commit is contained in:
parent
6944aa1eef
commit
3d2697c29b
|
|
@ -428,47 +428,47 @@ export const getExerciseByLevelIdForAdmin = async (req, res) => {
|
||||||
order: [["TITLE", "ASC"]],
|
order: [["TITLE", "ASC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!exercises || exercises.length === 0) {
|
let formattedExercises = [];
|
||||||
return response(404, null, "No exercises found for this level", res);
|
|
||||||
|
if (exercises && exercises.length > 0) {
|
||||||
|
formattedExercises = exercises.map((exercise) => {
|
||||||
|
const exerciseData = { ...exercise.dataValues };
|
||||||
|
const questionType = exercise.QUESTION_TYPE;
|
||||||
|
|
||||||
|
if (questionType === "MCQ") {
|
||||||
|
if (exerciseData.multipleChoices) {
|
||||||
|
exerciseData.multipleChoices = exerciseData.multipleChoices.map(
|
||||||
|
(choice) => choice.dataValues
|
||||||
|
);
|
||||||
|
}
|
||||||
|
delete exerciseData.matchingPairs;
|
||||||
|
delete exerciseData.trueFalse;
|
||||||
|
} else if (questionType === "MPQ") {
|
||||||
|
if (exerciseData.matchingPairs) {
|
||||||
|
exerciseData.matchingPairs = exerciseData.matchingPairs.map(
|
||||||
|
(pair) => pair.dataValues
|
||||||
|
);
|
||||||
|
}
|
||||||
|
delete exerciseData.multipleChoices;
|
||||||
|
delete exerciseData.trueFalse;
|
||||||
|
} else if (questionType === "TFQ") {
|
||||||
|
if (exerciseData.trueFalse) {
|
||||||
|
exerciseData.trueFalse = exerciseData.trueFalse.map(
|
||||||
|
(tf) => tf.dataValues
|
||||||
|
);
|
||||||
|
}
|
||||||
|
delete exerciseData.multipleChoices;
|
||||||
|
delete exerciseData.matchingPairs;
|
||||||
|
} else {
|
||||||
|
delete exerciseData.multipleChoices;
|
||||||
|
delete exerciseData.matchingPairs;
|
||||||
|
delete exerciseData.trueFalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exerciseData;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const formattedExercises = exercises.map((exercise) => {
|
|
||||||
const exerciseData = { ...exercise.dataValues };
|
|
||||||
const questionType = exercise.QUESTION_TYPE;
|
|
||||||
|
|
||||||
if (questionType === "MCQ") {
|
|
||||||
if (exerciseData.multipleChoices) {
|
|
||||||
exerciseData.multipleChoices = exerciseData.multipleChoices.map(
|
|
||||||
(choice) => choice.dataValues
|
|
||||||
);
|
|
||||||
}
|
|
||||||
delete exerciseData.matchingPairs;
|
|
||||||
delete exerciseData.trueFalse;
|
|
||||||
} else if (questionType === "MPQ") {
|
|
||||||
if (exerciseData.matchingPairs) {
|
|
||||||
exerciseData.matchingPairs = exerciseData.matchingPairs.map(
|
|
||||||
(pair) => pair.dataValues
|
|
||||||
);
|
|
||||||
}
|
|
||||||
delete exerciseData.multipleChoices;
|
|
||||||
delete exerciseData.trueFalse;
|
|
||||||
} else if (questionType === "TFQ") {
|
|
||||||
if (exerciseData.trueFalse) {
|
|
||||||
exerciseData.trueFalse = exerciseData.trueFalse.map(
|
|
||||||
(tf) => tf.dataValues
|
|
||||||
);
|
|
||||||
}
|
|
||||||
delete exerciseData.multipleChoices;
|
|
||||||
delete exerciseData.matchingPairs;
|
|
||||||
} else {
|
|
||||||
delete exerciseData.multipleChoices;
|
|
||||||
delete exerciseData.matchingPairs;
|
|
||||||
delete exerciseData.trueFalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
return exerciseData;
|
|
||||||
});
|
|
||||||
|
|
||||||
const responsePayload = {
|
const responsePayload = {
|
||||||
NAME_SECTION: levelExists.levelTopic.topicSection.NAME_SECTION,
|
NAME_SECTION: levelExists.levelTopic.topicSection.NAME_SECTION,
|
||||||
NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC,
|
NAME_TOPIC: levelExists.levelTopic.NAME_TOPIC,
|
||||||
|
|
@ -498,7 +498,14 @@ export const createExercises = async (req, res) => {
|
||||||
const levelId = exercises[0]?.ID_LEVEL;
|
const levelId = exercises[0]?.ID_LEVEL;
|
||||||
let lastExercise = await models.Exercise.findOne({
|
let lastExercise = await models.Exercise.findOne({
|
||||||
where: { ID_LEVEL: levelId },
|
where: { ID_LEVEL: levelId },
|
||||||
order: [["TITLE", "DESC"]],
|
order: [
|
||||||
|
[
|
||||||
|
models.Sequelize.literal(
|
||||||
|
"CAST(SUBSTRING_INDEX(TITLE, ' ', -1) AS UNSIGNED)"
|
||||||
|
),
|
||||||
|
"DESC",
|
||||||
|
],
|
||||||
|
],
|
||||||
limit: 1,
|
limit: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,6 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
||||||
"ID_STUDENT_EXERCISE",
|
"ID_STUDENT_EXERCISE",
|
||||||
"ANSWER_STUDENT",
|
"ANSWER_STUDENT",
|
||||||
"IS_CORRECT",
|
"IS_CORRECT",
|
||||||
"RESULT_SCORE_STUDENT",
|
|
||||||
"TIME_STUDENT_EXC",
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -150,7 +148,7 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
message: "Student learning exercises retrieved successfully",
|
message: "Student learning exercises retrieved successfully",
|
||||||
data: {
|
payload: {
|
||||||
...stdLearning.toJSON(),
|
...stdLearning.toJSON(),
|
||||||
stdExercises: mappedExercises,
|
stdExercises: mappedExercises,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ export const learningHistory = async (req, res) => {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
order: [["STUDENT_START", "DESC"]],
|
order: [["STUDENT_FINISH", "DESC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!stdLearnings.length) {
|
if (!stdLearnings.length) {
|
||||||
|
|
@ -371,7 +371,7 @@ export const learningHistoryBySectionId = async (req, res) => {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
order: [["STUDENT_START", "DESC"]],
|
order: [["STUDENT_FINISH", "DESC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!stdLearnings.length) {
|
if (!stdLearnings.length) {
|
||||||
|
|
@ -473,7 +473,7 @@ export const learningHistoryByTopicId = async (req, res) => {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
order: [["STUDENT_START", "DESC"]],
|
order: [["STUDENT_FINISH", "DESC"]],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!stdLearnings.length) {
|
if (!stdLearnings.length) {
|
||||||
|
|
@ -536,6 +536,67 @@ export const learningHistoryByTopicId = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const recentStudentActivities = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const stdLearnings = await models.StdLearning.findAll({
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: models.User,
|
||||||
|
as: "learningUser",
|
||||||
|
attributes: ["ID", "NAME_USERS"],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: models.Student,
|
||||||
|
as: "students",
|
||||||
|
attributes: ["NISN"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: models.Level,
|
||||||
|
as: "level",
|
||||||
|
attributes: ["NAME_LEVEL"],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: models.Topic,
|
||||||
|
as: "levelTopic",
|
||||||
|
attributes: ["NAME_TOPIC"],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: models.Section,
|
||||||
|
as: "topicSection",
|
||||||
|
attributes: ["NAME_SECTION"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
order: [["STUDENT_FINISH", "DESC"]],
|
||||||
|
limit: 5,
|
||||||
|
});
|
||||||
|
|
||||||
|
const recentActivities = stdLearnings.map((learning) => ({
|
||||||
|
NISN: learning.learningUser?.students?.NISN || "N/A",
|
||||||
|
NAME_USERS: learning.learningUser?.NAME_USERS || "N/A",
|
||||||
|
NAME_SECTION:
|
||||||
|
learning.level?.levelTopic?.topicSection?.NAME_SECTION || "N/A",
|
||||||
|
NAME_TOPIC: learning.level?.levelTopic?.NAME_TOPIC || "N/A",
|
||||||
|
NAME_LEVEL: learning.level?.NAME_LEVEL || "N/A",
|
||||||
|
SCORE: learning.SCORE || "N/A",
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!recentActivities.length) {
|
||||||
|
return res.status(404).json({ message: "No recent activities found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(200).json({ recentActivities });
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json({ message: "Internal Server Error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getLastCreatedStdLearningByLevelId = async (req, res) => {
|
export const getLastCreatedStdLearningByLevelId = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import { getStdLearnings, getStdLearningById, createStdLearning, updateStdLearningById, learningScoreByStdLearningId, learningHistory, learningHistoryBySectionId, learningHistoryByTopicId, getLastCreatedStdLearningByLevelId } from "../../controllers/learningControllers/stdLearning.js";
|
import { getStdLearnings, getStdLearningById, createStdLearning, updateStdLearningById, learningScoreByStdLearningId, learningHistory, learningHistoryBySectionId, learningHistoryByTopicId, recentStudentActivities, getLastCreatedStdLearningByLevelId } from "../../controllers/learningControllers/stdLearning.js";
|
||||||
import { checkStdLearning } from "../../middlewares/checkStdLearning.js";
|
import { checkStdLearning } from "../../middlewares/checkStdLearning.js";
|
||||||
import { verifyLoginUser } from "../../middlewares/User/authUser.js";
|
import { verifyLoginUser } from "../../middlewares/User/authUser.js";
|
||||||
|
|
||||||
|
|
@ -7,6 +7,8 @@ const router = express.Router();
|
||||||
|
|
||||||
router.get("/stdLearning", verifyLoginUser, getStdLearnings);
|
router.get("/stdLearning", verifyLoginUser, getStdLearnings);
|
||||||
|
|
||||||
|
router.get("/stdLearning/activities", verifyLoginUser, recentStudentActivities);
|
||||||
|
|
||||||
router.get("/stdLearning/:id", verifyLoginUser, getStdLearningById);
|
router.get("/stdLearning/:id", verifyLoginUser, getStdLearningById);
|
||||||
|
|
||||||
router.get("/stdLearning/score/:stdLearningId", verifyLoginUser, learningScoreByStdLearningId);
|
router.get("/stdLearning/score/:stdLearningId", verifyLoginUser, learningScoreByStdLearningId);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user