Fix bug with calendar

This commit is contained in:
Senad Uka
2019-08-26 05:03:16 +02:00
parent 2ac4074d94
commit 1447d800bf
9 changed files with 245 additions and 59 deletions

View File

@@ -2,7 +2,12 @@
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
const { chargeBookingChanges } = require('./bookingChangeCharges');
const {
getIncidentsFromChanges,
bulkWriteBookingChangeIncidents,
getReservationsIncidentsForRemoval,
deleteBookingChangeIncidents,
} = require('./bookingChangeCharges');
const { bulkWriteChanges } = require('./bookingChangeLog');
const checkBookingChanges = () => {
@@ -13,9 +18,28 @@ const checkBookingChanges = () => {
.then((changes) => {
bulkWriteChanges(changes)
.then(() => {
chargeBookingChanges(changes)
.then(() => {
resolve(true);
getIncidentsFromChanges(changes)
.then(({incidents, reservationsForAdditionalCheck}) => {
bulkWriteBookingChangeIncidents(incidents)
.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);