Navbar, bulk email (fix toggle error), department consolidated

This commit is contained in:
Harshitha Shetty
2025-02-04 12:07:13 +05:30
parent 1e91864769
commit 4a3154752f
7 changed files with 412 additions and 20 deletions

View File

@@ -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;