Files
old-crm-integration/services/integration/checkBookingChange.js
2019-07-25 06:53:32 +02:00

45 lines
1.7 KiB
JavaScript

'use strict';
const { fetchAllBookings, bulkWriteReservationsWithChangesTracking } = require('../officeRnD/bookings');
const { chargeBookingChanges } = require('./bookingChangeCharges');
const { bulkWriteChanges } = require('./bookingChangeLog');
const checkBookingChanges = () => {
return new Promise((resolve, reject) => {
fetchAllBookings()
.then((reservations) => {
bulkWriteReservationsWithChangesTracking(reservations)
.then((changes) => {
bulkWriteChanges(changes)
.then(() => {
chargeBookingChanges(changes)
.then(() => {
resolve(true);
})
.catch((error) => {
console.log('Error creating charges ', error);
reject(error);
});
})
.catch((error) => {
console.log('Error bulk write booking reservation change log :', error);
reject(error);
});
})
.catch((error) => {
console.log('Error bulk write booking reservations :', error);
reject(error);
});
})
.catch((error) => {
console.log('Error fetching bookings from ORD ', error);
reject(error);
});
});
};
module.exports = {
checkBookingChanges
};