filter
This commit is contained in:
@@ -40,7 +40,7 @@ const generateAppointmentCSV = async (req, res) => {
|
||||
});
|
||||
|
||||
await csvWriter.writeRecords(csvData);
|
||||
res.status(200).json({ message: "CSV generated successfully", path: "/generated_csv/appointments.csv" });
|
||||
res.status(200).json({ message: "CSV generated successfully", path: "./generated_csv/appointments.csv" });
|
||||
} catch (error) {
|
||||
console.error("Error generating CSV:", error);
|
||||
res.status(500).json({ message: "Failed to generate CSV" });
|
||||
|
||||
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;
|
||||
@@ -14,6 +14,7 @@ const courseRoutes = require("./routes/courseRoutes");
|
||||
const facultyRoutes = require("./routes/facultyRoutes");
|
||||
const appointmentRoutes = require("./routes/appointmentRoutes");
|
||||
const optionsRoutes = require("./routes/optionsRoutes");
|
||||
const consolidatedRoutes = require("./routes/consolidatedRoutes");
|
||||
const Course = require("./models/Course");
|
||||
|
||||
// MongoDB Connection
|
||||
@@ -50,8 +51,9 @@ require("./config/passport");
|
||||
app.use("/password", authRoutes);
|
||||
app.use("/api/courses", courseRoutes);
|
||||
app.use("/api/faculty", facultyRoutes);
|
||||
app.use("/api/appointments", appointmentRoutes); // Appointment route handles the updated structure
|
||||
app.use("/api/appointments", appointmentRoutes);
|
||||
app.use("/api/options", optionsRoutes);
|
||||
app.use("/api/data", consolidatedRoutes); // Moved after `app` initialization
|
||||
|
||||
// Google OAuth Routes
|
||||
app.get(
|
||||
@@ -157,8 +159,8 @@ app.patch("/api/courses/:courseId", async (req, res) => {
|
||||
const { courseId } = req.params;
|
||||
const { status } = req.body;
|
||||
|
||||
console.log('Request params:', req.params);
|
||||
console.log('Request body:', req.body);
|
||||
console.log("Request params:", req.params);
|
||||
console.log("Request body:", req.body);
|
||||
|
||||
if (!status) {
|
||||
console.error("Status is missing in the request body.");
|
||||
@@ -168,8 +170,8 @@ app.patch("/api/courses/:courseId", async (req, res) => {
|
||||
try {
|
||||
const updatedCourse = await Course.findOneAndUpdate(
|
||||
{ courseId: courseId }, // Use courseId field for finding the course
|
||||
{ status }, // Update the status field
|
||||
{ new: true }// Return the updated document
|
||||
{ status }, // Update the status field
|
||||
{ new: true } // Return the updated document
|
||||
);
|
||||
|
||||
if (!updatedCourse) {
|
||||
@@ -184,8 +186,6 @@ app.patch("/api/courses/:courseId", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Serve React Build Files
|
||||
app.use(express.static(path.join(__dirname, "../client/build")));
|
||||
app.get("*", (req, res) =>
|
||||
|
||||
Reference in New Issue
Block a user