forked from CSI-KJSCE/appointment_to_examiner
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
const express = require("express");
|
|
const router = express.Router();
|
|
const Appointment = require("../models/Appointment");
|
|
const Course = require("../models/Course");
|
|
const Faculty = require("../models/Faculty");
|
|
|
|
router.get("/consolidated-table", async (req, res) => {
|
|
try {
|
|
const appointments = await Appointment.find();
|
|
const courses = await Course.find();
|
|
const faculties = await Faculty.find();
|
|
|
|
// Group by facultyId and courseId
|
|
const groupedData = {};
|
|
|
|
appointments.forEach((appointment) => {
|
|
const key = `${appointment.facultyId}-${appointment.courseId}`;
|
|
if (!groupedData[key]) {
|
|
groupedData[key] = {
|
|
facultyId: appointment.facultyId,
|
|
courseId: appointment.courseId,
|
|
facultyName: appointment.facultyName,
|
|
courseName: appointment.courseName,
|
|
semester: "",
|
|
examType: "",
|
|
year: "",
|
|
marks: "100+25", // Dummy value, replace with actual logic
|
|
affiliation: "KJSCE", // Replace with actual value
|
|
qualification: "M.E.", // Replace with actual value
|
|
experience: "20+", // Dummy value
|
|
tasks: new Set(), // Use a set to avoid duplicate tasks
|
|
};
|
|
}
|
|
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") ? "✔" : "",
|
|
facultyId: `${data.facultyId}`
|
|
}));
|
|
|
|
res.status(200).json(tableData);
|
|
} catch (error) {
|
|
console.error("Error fetching consolidated table data:", error);
|
|
res.status(500).json({ message: "Failed to fetch consolidated table data" });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|