refactor: get topic for admin and api route

This commit is contained in:
elangptra 2024-11-06 08:04:51 +07:00
parent bef9ecc325
commit 2285389b12
3 changed files with 71 additions and 12 deletions

View File

@ -105,10 +105,15 @@ export const getTopicForAdmin = async (req, res) => {
[models.Op.like]: `%${search}%`,
},
},
{
DESCRIPTION_TOPIC: {
[models.Op.like]: `%${search}%`,
},
}
],
}),
},
attributes: ["ID_TOPIC", "NAME_TOPIC", "TIME_TOPIC"],
attributes: ["ID_TOPIC", "NAME_TOPIC", "DESCRIPTION_TOPIC", "TIME_TOPIC"],
include: [
{
model: models.Section,
@ -124,6 +129,7 @@ export const getTopicForAdmin = async (req, res) => {
ID_TOPIC: topic.ID_TOPIC,
NAME_SECTION: topic.topicSection.NAME_SECTION,
NAME_TOPIC: topic.NAME_TOPIC,
DESCRIPTION_TOPIC: topic.DESCRIPTION_TOPIC,
TIME_TOPIC: topic.TIME_TOPIC,
}));

View File

@ -577,7 +577,60 @@ export const deleteUserById = async (req, res) => {
return response(404, null, "User not found", res);
}
const studentLearnings = await models.StdLearning.findAll({
where: { ID: id },
attributes: ["ID_STUDENT_LEARNING"],
transaction,
});
const studentLearningIds = studentLearnings.map(
(sl) => sl.ID_STUDENT_LEARNING
);
if (studentLearningIds.length > 0) {
await models.Monitoring.destroy({
where: {
ID_STUDENT_LEARNING: studentLearningIds,
},
transaction,
});
await models.StdExercise.destroy({
where: {
ID_STUDENT_LEARNING: studentLearningIds,
},
transaction,
});
}
await models.StdLearning.destroy({
where: { ID: id },
transaction,
});
await models.Report.destroy({
where: { ID: id },
transaction,
});
if (user.ROLE === "teacher") {
const teacher = await models.Teacher.findOne({
where: { ID: id },
attributes: ["ID_GURU"],
transaction,
});
if (teacher) {
await models.Monitoring.update(
{ ID_GURU: null },
{
where: { ID_GURU: teacher.ID_GURU },
transaction,
}
);
await teacher.destroy({ transaction });
}
await models.Teacher.destroy({ where: { ID: id }, transaction });
} else if (user.ROLE === "student") {
await models.Student.destroy({ where: { ID: id }, transaction });

View File

@ -12,16 +12,16 @@ import monitoring_routes from "./monitoring/monitoring.js";
import report_routes from "./user/report.js";
const route = express();
route.use(user_routes);
route.use(auth_routes);
route.use(section_routes);
route.use(topic_routes);
route.use(level_routes);
route.use(exercise_routes);
route.use(stdLearning_routes);
route.use(stdExercise_routes);
route.use(class_routes);
route.use(monitoring_routes);
route.use(report_routes);
route.use("/api", user_routes);
route.use("/api", auth_routes);
route.use("/api", section_routes);
route.use("/api", topic_routes);
route.use("/api", level_routes);
route.use("/api", exercise_routes);
route.use("/api", stdLearning_routes);
route.use("/api", stdExercise_routes);
route.use("/api", class_routes);
route.use("/api", monitoring_routes);
route.use("/api", report_routes);
export default route;