|
|
@@ -3,7 +3,7 @@ import passport from "passport";
|
|
|
import {mongoose} from "mongoose";
|
|
|
import Appointment from "../schemas/appointmentSchema.js";
|
|
|
import Booking from "../schemas/bookingSchema.js";
|
|
|
-import {isDatePassed, isDueDatePassed} from "../utils.js";
|
|
|
+import {validateDates} from "../utils.js";
|
|
|
|
|
|
/**
|
|
|
* Router for handling appointments.
|
|
|
@@ -37,18 +37,7 @@ router.post('/create', function(req, res, next) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (isDatePassed(startDate, dueDate)) {
|
|
|
- res.status(400).json({ 'message': 'Due date is after start date' });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (isDueDatePassed(dueDate)) {
|
|
|
- res.status(400).json({ 'message': 'Due date is in the past' });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (isDatePassed(endDate, startDate)) {
|
|
|
- res.status(400).json({ 'message': 'End date is before start date' });
|
|
|
+ if (!validateDates(res, startDate, endDate, dueDate)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -71,8 +60,9 @@ router.post('/modify', function (req, res, next) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.log(appointmentId);
|
|
|
- console.log(user);
|
|
|
+ if (!validateDates(res, startDate, endDate, dueDate)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
Appointment.updateOne(
|
|
|
{ _id: appointmentId, user: user },
|