Files
appointment_to_examiner/server/routes/consolidatedRoutes.js
Harikrishnan Gopal e7fb1583d7 consolidated
2025-01-22 11:58:26 +05:30

50 lines
2.0 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 {
// Fetch all appointments
const appointments = await Appointment.find();
// Fetch all courses
const courses = await Course.find();
// Fetch all faculties
const faculties = await Faculty.find();
// Prepare data for the table
const tableData = appointments.map((appointment, index) => {
const course = courses.find((c) => c.courseId === appointment.courseId);
const faculty = faculties.find((f) => f.facultyId === appointment.facultyId);
return {
srNo: index + 1,
semester: course?.semester || "",
courseCode: course?.courseId || "",
courseName: course?.name || "",
examType: course?.scheme || "",
year: course?.program || "",
marks: "100+25", // Replace with actual marks logic if required
Name: faculty?.name || "",
affiliation: "KJSCE", // Replace with actual affiliation if needed
qualification: "M.E.", // Replace with actual qualification if needed
experience: "20+", // Replace with actual experience logic if required
oralPractical: appointment.task === "oralsPracticals" ? "✔" : "",
assessment: appointment.task === "assessment" ? "✔" : "",
reassessment: appointment.task === "reassessment" ? "✔" : "",
paperSetting: appointment.task === "paperSetting" ? "✔" : "",
moderation: appointment.task === "moderation" ? "✔" : "",
pwdPaperSetting: appointment.task === "pwdPaperSetter" ? "✔" : "",
};
});
res.status(200).json(tableData);
} catch (error) {
console.error("Error generating consolidated table:", error);
res.status(500).json({ message: "Failed to generate table" });
}
});
module.exports = router;