feat: student activities function and exercise model function
This commit is contained in:
parent
6944aa1eef
commit
3d2697c29b
|
|
@ -428,11 +428,10 @@ export const getExerciseByLevelIdForAdmin = async (req, res) => {
|
|||
order: [["TITLE", "ASC"]],
|
||||
});
|
||||
|
||||
if (!exercises || exercises.length === 0) {
|
||||
return response(404, null, "No exercises found for this level", res);
|
||||
}
|
||||
let formattedExercises = [];
|
||||
|
||||
const formattedExercises = exercises.map((exercise) => {
|
||||
if (exercises && exercises.length > 0) {
|
||||
formattedExercises = exercises.map((exercise) => {
|
||||
const exerciseData = { ...exercise.dataValues };
|
||||
const questionType = exercise.QUESTION_TYPE;
|
||||
|
||||
|
|
@ -468,6 +467,7 @@ export const getExerciseByLevelIdForAdmin = async (req, res) => {
|
|||
|
||||
return exerciseData;
|
||||
});
|
||||
}
|
||||
|
||||
const responsePayload = {
|
||||
NAME_SECTION: levelExists.levelTopic.topicSection.NAME_SECTION,
|
||||
|
|
@ -498,7 +498,14 @@ export const createExercises = async (req, res) => {
|
|||
const levelId = exercises[0]?.ID_LEVEL;
|
||||
let lastExercise = await models.Exercise.findOne({
|
||||
where: { ID_LEVEL: levelId },
|
||||
order: [["TITLE", "DESC"]],
|
||||
order: [
|
||||
[
|
||||
models.Sequelize.literal(
|
||||
"CAST(SUBSTRING_INDEX(TITLE, ' ', -1) AS UNSIGNED)"
|
||||
),
|
||||
"DESC",
|
||||
],
|
||||
],
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -119,8 +119,6 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
|||
"ID_STUDENT_EXERCISE",
|
||||
"ANSWER_STUDENT",
|
||||
"IS_CORRECT",
|
||||
"RESULT_SCORE_STUDENT",
|
||||
"TIME_STUDENT_EXC",
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
@ -150,7 +148,7 @@ export const getStudentAnswersByStdLearningId = async (req, res) => {
|
|||
|
||||
return res.status(200).json({
|
||||
message: "Student learning exercises retrieved successfully",
|
||||
data: {
|
||||
payload: {
|
||||
...stdLearning.toJSON(),
|
||||
stdExercises: mappedExercises,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ export const learningHistory = async (req, res) => {
|
|||
required: true,
|
||||
},
|
||||
],
|
||||
order: [["STUDENT_START", "DESC"]],
|
||||
order: [["STUDENT_FINISH", "DESC"]],
|
||||
});
|
||||
|
||||
if (!stdLearnings.length) {
|
||||
|
|
@ -371,7 +371,7 @@ export const learningHistoryBySectionId = async (req, res) => {
|
|||
required: true,
|
||||
},
|
||||
],
|
||||
order: [["STUDENT_START", "DESC"]],
|
||||
order: [["STUDENT_FINISH", "DESC"]],
|
||||
});
|
||||
|
||||
if (!stdLearnings.length) {
|
||||
|
|
@ -473,7 +473,7 @@ export const learningHistoryByTopicId = async (req, res) => {
|
|||
required: true,
|
||||
},
|
||||
],
|
||||
order: [["STUDENT_START", "DESC"]],
|
||||
order: [["STUDENT_FINISH", "DESC"]],
|
||||
});
|
||||
|
||||
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) => {
|
||||
try {
|
||||
if (!req.user) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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 { verifyLoginUser } from "../../middlewares/User/authUser.js";
|
||||
|
||||
|
|
@ -7,6 +7,8 @@ const router = express.Router();
|
|||
|
||||
router.get("/stdLearning", verifyLoginUser, getStdLearnings);
|
||||
|
||||
router.get("/stdLearning/activities", verifyLoginUser, recentStudentActivities);
|
||||
|
||||
router.get("/stdLearning/:id", verifyLoginUser, getStdLearningById);
|
||||
|
||||
router.get("/stdLearning/score/:stdLearningId", verifyLoginUser, learningScoreByStdLearningId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user