Navbar, bulk email (fix toggle error), department consolidated
This commit is contained in:
@@ -145,4 +145,75 @@ router.get("/course-consolidated", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/department-consolidated", async (req, res) => {
|
||||
try {
|
||||
const appointments = await Appointment.find();
|
||||
const courses = await Course.find();
|
||||
|
||||
// Group appointments by department and course
|
||||
const groupedByDepartment = {};
|
||||
|
||||
appointments.forEach((appointment) => {
|
||||
const course = courses.find((c) => c.courseId === appointment.courseId);
|
||||
|
||||
if (!course) return; // Skip if course not found
|
||||
|
||||
const department = course.department;
|
||||
|
||||
if (!groupedByDepartment[department]) {
|
||||
groupedByDepartment[department] = {
|
||||
department: department,
|
||||
courses: [],
|
||||
};
|
||||
}
|
||||
|
||||
// Find or create the course in the department
|
||||
let courseData = groupedByDepartment[department].courses.find(
|
||||
(c) => c.courseCode === appointment.courseId
|
||||
);
|
||||
|
||||
if (!courseData) {
|
||||
courseData = {
|
||||
courseCode: appointment.courseId,
|
||||
courseName: appointment.courseName,
|
||||
semester: course.semester,
|
||||
examType: course.scheme,
|
||||
year: course.program,
|
||||
oralPracticalTeachers: [],
|
||||
assessmentTeachers: [],
|
||||
reassessmentTeachers: [],
|
||||
paperSettingTeachers: [],
|
||||
moderationTeachers: [],
|
||||
pwdPaperSettingTeachers: [],
|
||||
};
|
||||
groupedByDepartment[department].courses.push(courseData);
|
||||
}
|
||||
|
||||
// Add the faculty name to the appropriate task
|
||||
if (appointment.task === "oralsPracticals") {
|
||||
courseData.oralPracticalTeachers.push(appointment.facultyName);
|
||||
} else if (appointment.task === "assessment") {
|
||||
courseData.assessmentTeachers.push(appointment.facultyName);
|
||||
} else if (appointment.task === "reassessment") {
|
||||
courseData.reassessmentTeachers.push(appointment.facultyName);
|
||||
} else if (appointment.task === "paperSetting") {
|
||||
courseData.paperSettingTeachers.push(appointment.facultyName);
|
||||
} else if (appointment.task === "moderation") {
|
||||
courseData.moderationTeachers.push(appointment.facultyName);
|
||||
} else if (appointment.task === "pwdPaperSetter") {
|
||||
courseData.pwdPaperSettingTeachers.push(appointment.facultyName);
|
||||
}
|
||||
});
|
||||
|
||||
// Convert to array format
|
||||
const consolidatedData = Object.values(groupedByDepartment);
|
||||
|
||||
res.status(200).json(consolidatedData);
|
||||
} catch (error) {
|
||||
console.error("Error fetching department consolidated data:", error);
|
||||
res.status(500).json({ message: "Failed to fetch department consolidated data" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user