From edefaf7cf95ae0491b492a2559306f51e90a5496 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 9 Jul 2019 14:17:36 +0200 Subject: [PATCH 1/3] modify bookingChangeIncidents table --- ...eId-column-in-booking-change-incidents-table.js | 11 +++++++++++ ...eId-column-in-booking-change-incidents-table.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 migrations/20190709120748-rename-resourceId-column-in-booking-change-incidents-table.js create mode 100644 migrations/20190709121128-add-new-resourceId-column-in-booking-change-incidents-table.js diff --git a/migrations/20190709120748-rename-resourceId-column-in-booking-change-incidents-table.js b/migrations/20190709120748-rename-resourceId-column-in-booking-change-incidents-table.js new file mode 100644 index 0000000..dc892da --- /dev/null +++ b/migrations/20190709120748-rename-resourceId-column-in-booking-change-incidents-table.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.renameColumn('bookingChangeIncidents', 'resourceId', 'oldResourceId'); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.renameColumn('bookingChangeIncidents', 'oldResourceId', 'resourceId'); + } +}; diff --git a/migrations/20190709121128-add-new-resourceId-column-in-booking-change-incidents-table.js b/migrations/20190709121128-add-new-resourceId-column-in-booking-change-incidents-table.js new file mode 100644 index 0000000..1b568b0 --- /dev/null +++ b/migrations/20190709121128-add-new-resourceId-column-in-booking-change-incidents-table.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.addColumn('bookingChangeIncidents', 'newResourceId', { + type: Sequelize.TEXT, + after: 'oldResourceId', + }); + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.removeColumn('bookingChangeIncidents', 'newResourceId'); + } +}; From ad9bdfa6060b176c60b538b238067cd81a331c7d Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 9 Jul 2019 15:05:36 +0200 Subject: [PATCH 2/3] track room change for booking change incidents --- models/bookingChangeIncident.js | 3 ++- services/integration/bookingChangeCharges.js | 9 ++++++--- services/officeRnD/bookings.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/models/bookingChangeIncident.js b/models/bookingChangeIncident.js index 1a91f1e..a5e9a75 100644 --- a/models/bookingChangeIncident.js +++ b/models/bookingChangeIncident.js @@ -4,7 +4,8 @@ module.exports = (sequelize, DataTypes) => { const bookingChangeIncident = sequelize.define('bookingChangeIncident', { reservationId: DataTypes.TEXT, memberId: DataTypes.TEXT, - resourceId: DataTypes.TEXT, + oldResourceId: DataTypes.TEXT, + newResourceId: DataTypes.TEXT, oldBookingStart: DataTypes.DATE, oldBookingEnd: DataTypes.DATE, newBookingStart: DataTypes.DATE, diff --git a/services/integration/bookingChangeCharges.js b/services/integration/bookingChangeCharges.js index 13d47b2..e46a691 100644 --- a/services/integration/bookingChangeCharges.js +++ b/services/integration/bookingChangeCharges.js @@ -22,12 +22,14 @@ const bulkWriteBookingChangeIncidents = (incidents) => { const chargeBookingChanges = (changes) => { return new Promise((resolve, reject) => { + console.log(changes); if (Array.isArray(changes)){ const incidents = []; const errors = []; changes.forEach((change) => { const { oldReservation, newReservation } = change; if (oldReservation && newReservation){ + const oldResourceId = oldReservation.resourceId; const oldStart = oldReservation.start ? moment.utc(oldReservation.start) : null; const oldEnd = oldReservation.end ? moment.utc(oldReservation.end) : null; @@ -56,14 +58,14 @@ const chargeBookingChanges = (changes) => { // Check if member shortened the reservation if (newReservationLength < oldReservationLength){ - const differenceInLength = oldReservationLength - newReservationLength; const chargeFee = differenceInLength*hourlyRate*BOOKING_CHANGE_PERCENTAGE_CHARGE/100; const incident = { reservationId, memberId, - resourceId, + oldResourceId: oldResourceId || newReservation.resourceId, + newResourceId: newReservation.resourceId, oldBookingStart: oldReservation.start, oldBookingEnd: oldReservation.end, newBookingStart: newReservation.start, @@ -82,7 +84,8 @@ const chargeBookingChanges = (changes) => { const incident = { reservationId, memberId, - resourceId, + oldResourceId: oldResourceId || newReservation.resourceId, + newResourceId: newReservation.resourceId, oldBookingStart: oldReservation.start, oldBookingEnd: oldReservation.end, newBookingStart: newReservation.start, diff --git a/services/officeRnD/bookings.js b/services/officeRnD/bookings.js index 3a63a6c..650b7aa 100644 --- a/services/officeRnD/bookings.js +++ b/services/officeRnD/bookings.js @@ -174,7 +174,7 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => { const changedKeys = instance.changed(); const previous = instance.previous(); - const lookupKeys = ['start', 'end']; + const lookupKeys = ['start', 'end', 'resourceId']; let realChange = false; lookupKeys.forEach((key) => { From 98899d6826299d27ca61a8834959da92f0e8e451 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Fri, 12 Jul 2019 04:41:34 +0200 Subject: [PATCH 3/3] remove console log --- services/integration/bookingChangeCharges.js | 1 - 1 file changed, 1 deletion(-) diff --git a/services/integration/bookingChangeCharges.js b/services/integration/bookingChangeCharges.js index e46a691..06a9f8c 100644 --- a/services/integration/bookingChangeCharges.js +++ b/services/integration/bookingChangeCharges.js @@ -22,7 +22,6 @@ const bulkWriteBookingChangeIncidents = (incidents) => { const chargeBookingChanges = (changes) => { return new Promise((resolve, reject) => { - console.log(changes); if (Array.isArray(changes)){ const incidents = []; const errors = [];