Charges/invoices update
This commit is contained in:
@@ -174,7 +174,7 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
||||
const changedKeys = instance.changed();
|
||||
const previous = instance.previous();
|
||||
|
||||
const lookupKeys = ['start', 'end'];
|
||||
const lookupKeys = ['start', 'end', 'resourceId', 'canceled'];
|
||||
|
||||
let realChange = false;
|
||||
lookupKeys.forEach((key) => {
|
||||
@@ -184,6 +184,8 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
||||
}
|
||||
});
|
||||
|
||||
instance.setDataValue('hourlyRate', previous.hourlyRate);
|
||||
|
||||
if (realChange){
|
||||
changes.push({
|
||||
oldReservation: previous,
|
||||
@@ -193,25 +195,41 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
||||
});
|
||||
|
||||
reservations.forEach((reservation) => {
|
||||
asyncJobs.push(
|
||||
db.bookingReservation.update(reservation, {
|
||||
where: {
|
||||
reservationId: reservation.reservationId,
|
||||
},
|
||||
returning: true,
|
||||
individualHooks: true,
|
||||
})
|
||||
.then(([updateCount, updatedInstances]) => {
|
||||
if (updateCount === 0){
|
||||
db.bookingReservation.upsert(reservation);
|
||||
}
|
||||
const asyncReservationUpdate = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.bookingReservation.update(reservation, {
|
||||
where: {
|
||||
reservationId: reservation.reservationId,
|
||||
},
|
||||
returning: true,
|
||||
individualHooks: true,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error updating');
|
||||
console.log(error);
|
||||
reject(error);
|
||||
})
|
||||
);
|
||||
.then(([updateCount, updatedInstances]) => {
|
||||
if (updateCount === 0){
|
||||
const oldReservation = {
|
||||
start: null,
|
||||
end: null,
|
||||
resourceId: null,
|
||||
};
|
||||
|
||||
changes.push({
|
||||
oldReservation,
|
||||
newReservation: reservation,
|
||||
});
|
||||
resolve(db.bookingReservation.upsert(reservation));
|
||||
}else{
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error updating');
|
||||
console.log(error);
|
||||
reject(error);
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
asyncJobs.push(asyncReservationUpdate());
|
||||
});
|
||||
|
||||
Promise.all(asyncJobs)
|
||||
|
||||
Reference in New Issue
Block a user