forked from CSI-KJSCE/appointment_to_examiner
added exam period in frontend and in database
This commit is contained in:
@@ -2,19 +2,16 @@ const mongoose = require("mongoose");
|
||||
const { v4: uuidv4 } = require("uuid");
|
||||
|
||||
const AppointmentSchema = new mongoose.Schema({
|
||||
appointmentId: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
default: uuidv4
|
||||
},
|
||||
appointmentId: { type: String, required: true, unique: true, default: uuidv4 },
|
||||
facultyId: { type: String, required: true },
|
||||
facultyName: { type: String, required: true },
|
||||
courseId: { type: String, required: true },
|
||||
courseName: { type: String, required: true },
|
||||
task: { type: String, required: true },
|
||||
examPeriod: { type: String, required: true }, // New field for exam period
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("Appointment", AppointmentSchema);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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