|
|
@@ -30,9 +30,9 @@ router.use((req, res, next) => {
|
|
|
*/
|
|
|
router.post('/create', function(req, res, next) {
|
|
|
const user = req.userId;
|
|
|
- const { title, description, dueDate, place, duration, times, inputs } = req.body;
|
|
|
+ const { title, description, dueDate, place, duration, times, inputs, timeSpans } = req.body;
|
|
|
|
|
|
- if (!title || title.length === 0 || !dueDate || !description || !duration || !place || !times || !inputs) {
|
|
|
+ if (!title || title.length === 0 || !dueDate || !description || !duration || !place || !times || !inputs || !timeSpans) {
|
|
|
res.status(400).json({ 'message': 'Empty parameter' });
|
|
|
return;
|
|
|
}
|
|
|
@@ -53,7 +53,7 @@ router.post('/create', function(req, res, next) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const newTask = new Appointment({ user, title, description, dueDate, place, duration, times, inputs });
|
|
|
+ const newTask = new Appointment({ user, title, description, dueDate, place, duration, times, inputs, timeSpans });
|
|
|
|
|
|
newTask.save()
|
|
|
.then(doc => res.json({ "id": doc._id }))
|
|
|
@@ -66,8 +66,8 @@ router.post('/create', function(req, res, next) {
|
|
|
router.post('/modify', function (req, res, next) {
|
|
|
const user = req.userId;
|
|
|
|
|
|
- const { appointmentId, title, description, dueDate, place, times, inputs } = req.body;
|
|
|
- if (!title || !dueDate || !description || !startDate || !endDate || !times || !inputs) {
|
|
|
+ const { appointmentId, title, description, dueDate, place, times, inputs, timeSpans } = req.body;
|
|
|
+ if (!title || !dueDate || !description || !times || !inputs || !timeSpans) {
|
|
|
res.status(400).json({ 'error': 'Empty parameter' });
|
|
|
return;
|
|
|
}
|
|
|
@@ -79,7 +79,7 @@ router.post('/modify', function (req, res, next) {
|
|
|
|
|
|
Appointment.updateOne(
|
|
|
{ _id: appointmentId, user: user },
|
|
|
- { $set: { title, description, dueDate, place, times, inputs } }
|
|
|
+ { $set: { title, description, dueDate, place, times, inputs, timeSpans } }
|
|
|
)
|
|
|
.then(result => {
|
|
|
if (result.modifiedCount === 1) {
|
|
|
@@ -93,17 +93,53 @@ router.post('/modify', function (req, res, next) {
|
|
|
.catch(err => res.status(404).json({ 'message': 'Not found' }));
|
|
|
});
|
|
|
|
|
|
+/**
|
|
|
+ * Lock an existing appointment by modifying the due date.
|
|
|
+ */
|
|
|
+router.post('/lock', function (req, res, next) {
|
|
|
+ const user = req.userId;
|
|
|
+
|
|
|
+ const { appointmentId } = req.body;
|
|
|
+ if (!appointmentId) {
|
|
|
+ res.status(400).json({ 'error': 'Empty parameter' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const dueDate = new Date();
|
|
|
+
|
|
|
+ Appointment.updateOne(
|
|
|
+ { _id: appointmentId, user: user },
|
|
|
+ { $set: { dueDate } }
|
|
|
+ )
|
|
|
+ .then(result => {
|
|
|
+ if (result.modifiedCount === 1) {
|
|
|
+ console.log("Successfully updated the document.");
|
|
|
+ res.json({ "id": appointmentId });
|
|
|
+ } else {
|
|
|
+ console.log("Document not updated");
|
|
|
+ res.status(500).json({ 'message': 'Document has not changed' });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => res.status(404).json({ 'message': 'Not found' }));
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Delete an appointment.
|
|
|
*/
|
|
|
router.delete('/delete', function (req, res, next) {
|
|
|
const user = req.userId;
|
|
|
const {appointmentId} = req.body;
|
|
|
+ console.log(req.body);
|
|
|
if (!appointmentId) {
|
|
|
res.status(400).json({ 'message': 'Invalid parameter' });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ Booking.deleteMany({ appointment: appointmentId })
|
|
|
+ .then(result => {})
|
|
|
+ .catch(err => res.status(500).json({ 'message': err }));
|
|
|
+
|
|
|
Appointment.deleteOne({ _id: appointmentId, user: user })
|
|
|
.then(result => {
|
|
|
if (result.deletedCount === 1) {
|