consolidated

This commit is contained in:
Harikrishnan Gopal
2025-01-23 10:58:28 +05:30
parent b8e30b5f3b
commit f17f533cc0

View File

@@ -6,43 +6,69 @@ const Faculty = require("../models/Faculty");
router.get("/consolidated-table", async (req, res) => { router.get("/consolidated-table", async (req, res) => {
try { try {
// Fetch all appointments
const appointments = await Appointment.find(); const appointments = await Appointment.find();
// Fetch all courses
const courses = await Course.find(); const courses = await Course.find();
// Fetch all faculties
const faculties = await Faculty.find(); const faculties = await Faculty.find();
// Prepare data for the table // Group by facultyId and courseId
const tableData = appointments.map((appointment, index) => { const groupedData = {};
const course = courses.find((c) => c.courseId === appointment.courseId);
const faculty = faculties.find((f) => f.facultyId === appointment.facultyId);
return { appointments.forEach((appointment) => {
srNo: index + 1, const key = `${appointment.facultyId}-${appointment.courseId}`;
semester: course?.semester || "", if (!groupedData[key]) {
courseCode: course?.courseId || "", groupedData[key] = {
courseName: course?.name || "", facultyId: appointment.facultyId,
examType: course?.scheme || "", courseId: appointment.courseId,
year: course?.program || "", facultyName: appointment.facultyName,
marks: "100+25", // Replace with actual marks logic if required courseName: appointment.courseName,
Name: faculty?.name || "", semester: "",
affiliation: "KJSCE", // Replace with actual affiliation if needed examType: "",
qualification: "M.E.", // Replace with actual qualification if needed year: "",
experience: "20+", // Replace with actual experience logic if required marks: "100+25", // Dummy value, replace with actual logic
oralPractical: appointment.task === "oralsPracticals" ? "✔" : "", affiliation: "KJSCE", // Replace with actual value
assessment: appointment.task === "assessment" ? "✔" : "", qualification: "M.E.", // Replace with actual value
reassessment: appointment.task === "reassessment" ? "✔" : "", experience: "20+", // Dummy value
paperSetting: appointment.task === "paperSetting" ? "✔" : "", tasks: new Set(), // Use a set to avoid duplicate tasks
moderation: appointment.task === "moderation" ? "✔" : "", };
pwdPaperSetting: appointment.task === "pwdPaperSetter" ? "✔" : "", }
}; groupedData[key].tasks.add(appointment.task);
}); });
// Add course details to the grouped data
Object.values(groupedData).forEach((data) => {
const course = courses.find((c) => c.courseId === data.courseId);
if (course) {
data.semester = course.semester;
data.examType = course.scheme;
data.year = course.program;
}
});
// Format the tasks into separate columns
const tableData = Object.values(groupedData).map((data, index) => ({
srNo: index + 1,
semester: data.semester,
courseCode: data.courseId,
courseName: data.courseName,
examType: data.examType,
year: data.year,
marks: data.marks,
Name: data.facultyName,
affiliation: data.affiliation,
qualification: data.qualification,
experience: data.experience,
oralPractical: data.tasks.has("oralsPracticals") ? "✔" : "",
assessment: data.tasks.has("assessment") ? "✔" : "",
reassessment: data.tasks.has("reassessment") ? "✔" : "",
paperSetting: data.tasks.has("paperSetting") ? "✔" : "",
moderation: data.tasks.has("moderation") ? "✔" : "",
pwdPaperSetting: data.tasks.has("pwdPaperSetter") ? "✔" : "",
}));
res.status(200).json(tableData); res.status(200).json(tableData);
} catch (error) { } catch (error) {
console.error("Error generating consolidated table:", error); console.error("Error fetching consolidated table data:", error);
res.status(500).json({ message: "Failed to generate table" }); res.status(500).json({ message: "Failed to fetch consolidated table data" });
} }
}); });