forked from CSI-KJSCE/appointment_to_examiner
added exam period in frontend and in database
This commit is contained in:
@@ -7,17 +7,22 @@ const Course = require("../models/Course");
|
||||
// Save multiple appointments
|
||||
router.post("/", async (req, res) => {
|
||||
try {
|
||||
const { appointments } = req.body; // Expecting an array of appointments
|
||||
const { appointments } = req.body;
|
||||
if (!appointments || !Array.isArray(appointments)) {
|
||||
return res.status(400).json({ error: "Invalid or missing data" });
|
||||
}
|
||||
|
||||
const savedAppointments = [];
|
||||
for (const appointment of appointments) {
|
||||
const { facultyId, courseId, tasks } = appointment;
|
||||
const { facultyId, courseId, tasks, examPeriod } = appointment;
|
||||
|
||||
// Validate input data
|
||||
if (!facultyId || !courseId || !Array.isArray(tasks) || tasks.length === 0) {
|
||||
if (
|
||||
!facultyId ||
|
||||
!courseId ||
|
||||
!Array.isArray(tasks) ||
|
||||
tasks.length === 0 ||
|
||||
!examPeriod
|
||||
) {
|
||||
return res.status(400).json({ error: "Invalid appointment data" });
|
||||
}
|
||||
|
||||
@@ -30,7 +35,6 @@ router.post("/", async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Save each task as a separate appointment
|
||||
for (const task of tasks) {
|
||||
const newAppointment = new Appointment({
|
||||
facultyId,
|
||||
@@ -38,6 +42,7 @@ router.post("/", async (req, res) => {
|
||||
courseId,
|
||||
courseName: course.name,
|
||||
task,
|
||||
examPeriod,
|
||||
});
|
||||
const savedAppointment = await newAppointment.save();
|
||||
savedAppointments.push(savedAppointment);
|
||||
|
||||
Reference in New Issue
Block a user