- ++Booking List
- ++Delete a Booking also for the Admin.
This commit is contained in:
@@ -27,18 +27,19 @@ function sendNotif(res, idapp, user, recbooking) {
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
tools.mylog('INIZIO - booking');
|
||||
// tools.mylog('req.body', req.body);
|
||||
const body = _.pick(req.body, tools.allfieldBooking());
|
||||
const id = body.id_bookedevent;
|
||||
const fieldtochange = _.pick(req.body, tools.allfieldBookingChange());
|
||||
const myrec = _.pick(req.body, tools.allfieldBooking());
|
||||
const id = myrec._id;
|
||||
const fieldtochange = _.pick(myrec, tools.allfieldBookingChange());
|
||||
|
||||
tools.mylog('crea Booking');
|
||||
const booking = new Booking(body);
|
||||
const booking = new Booking(myrec);
|
||||
|
||||
const check = tools.checkUserOk(booking.userId, req.user._id);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
|
||||
// Modify:
|
||||
return Booking.findOne({ id_bookedevent: id })
|
||||
.then(trovato => {
|
||||
// console.log('trovato', trovato);
|
||||
@@ -49,7 +50,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
}).then((recbooking) => {
|
||||
// tools.mylog('booking:', booking);
|
||||
// tools.mylog('already exist');
|
||||
sendNotif(res, body.idapp, req.user, recbooking);
|
||||
sendNotif(res, myrec.idapp, req.user, recbooking);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recbooking._id });
|
||||
});
|
||||
} else {
|
||||
@@ -61,19 +62,42 @@ router.post('/', authenticate, (req, res) => {
|
||||
|
||||
Booking.findById(idobj)
|
||||
.then((recbooking) => {
|
||||
sendNotif(res, body.idapp, req.user, recbooking);
|
||||
sendNotif(res, myrec.idapp, req.user, recbooking);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recbooking._id });
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
|
||||
console.log('DELETE Booking');
|
||||
const id = req.params.id;
|
||||
const notify = req.params.notify;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
Booking.findByIdAndRemove(id).then((recbooking) => {
|
||||
if (!recbooking) {
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
if (notify === '1')
|
||||
sendNotif(res, idapp, req.user, recbooking);
|
||||
|
||||
tools.mylog('DELETED ', recbooking.descr, recbooking._id);
|
||||
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recbooking._id });
|
||||
|
||||
}).catch((e) => {
|
||||
res.status(400).send();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
router.get('/:userId/:idapp/:sall', authenticate, (req, res) => {
|
||||
const userId = req.params.userId;
|
||||
const idapp = req.params.idapp;
|
||||
const sall = req.params.sall;
|
||||
// var category = req.params.category;
|
||||
|
||||
tools.mylog('GET BOOKINGS : ', req.params);
|
||||
@@ -88,7 +112,7 @@ router.get('/:userId/:idapp', authenticate, (req, res) => {
|
||||
}
|
||||
|
||||
// Extract all the todos of the userId only
|
||||
Booking.findAllByUserIdAndIdApp(userId, idapp).then((bookedevent) => {
|
||||
Booking.findAllByUserIdAndIdApp(userId, idapp, sall).then((bookedevent) => {
|
||||
res.send({ bookedevent });
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user