remove incidents if new duration is longer than initial duration

This commit is contained in:
Bilal Catic
2019-08-24 09:26:52 +02:00
parent 934ffa90a7
commit 9c855692b7
3 changed files with 154 additions and 36 deletions

View File

@@ -2,7 +2,12 @@
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
const { getIncidentsFromChanges, bulkWriteBookingChangeIncidents } = require('./bookingChangeCharges');
const {
getIncidentsFromChanges,
bulkWriteBookingChangeIncidents,
getReservationsIncidentsForRemoval,
deleteBookingChangeIncidents,
} = require('./bookingChangeCharges');
const { bulkWriteChanges } = require('./bookingChangeLog');
const checkBookingChanges = () => {
@@ -14,10 +19,27 @@ const checkBookingChanges = () => {
bulkWriteChanges(changes)
.then(() => {
getIncidentsFromChanges(changes)
.then((incidents) => {
.then(({incidents, reservationsForAdditionalCheck}) => {
bulkWriteBookingChangeIncidents(incidents)
.then(() => resolve(true))
.catch((error) => reject(error));
.then(() => {
getReservationsIncidentsForRemoval(reservationsForAdditionalCheck)
.then((incidentsToRemove) => {
deleteBookingChangeIncidents(incidentsToRemove)
.then(() => resolve(true))
.catch((error) => {
console.log('Error deleting incidents : ', error);
reject(error);
});
})
.catch((error) => {
console.log('Failed to fetch reservations possible incidents for removal', error);
reject(error);
});
})
.catch((error) => {
console.log('error', error);
reject(error);
});
})
.catch((error) => {
console.log('Error creating charges ', error);