filter
This commit is contained in:
34
server/routes/consolidatedRoutes.js
Normal file
34
server/routes/consolidatedRoutes.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const Appointment = require("../models/Appointment");
|
||||
|
||||
router.get("/consolidated", async (req, res) => {
|
||||
try {
|
||||
const appointments = await Appointment.find();
|
||||
|
||||
// Group data by faculty
|
||||
const groupedData = appointments.reduce((acc, appointment) => {
|
||||
if (!acc[appointment.facultyId]) {
|
||||
acc[appointment.facultyId] = {
|
||||
facultyId: appointment.facultyId,
|
||||
facultyName: appointment.facultyName,
|
||||
tasks: [],
|
||||
};
|
||||
}
|
||||
acc[appointment.facultyId].tasks.push({
|
||||
courseId: appointment.courseId,
|
||||
courseName: appointment.courseName,
|
||||
task: appointment.task,
|
||||
});
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
const result = Object.values(groupedData);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
console.error("Error fetching consolidated data:", error);
|
||||
res.status(500).json({ message: "Failed to fetch consolidated data" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user