track room change for booking change incidents
This commit is contained in:
@@ -4,7 +4,8 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
const bookingChangeIncident = sequelize.define('bookingChangeIncident', {
|
const bookingChangeIncident = sequelize.define('bookingChangeIncident', {
|
||||||
reservationId: DataTypes.TEXT,
|
reservationId: DataTypes.TEXT,
|
||||||
memberId: DataTypes.TEXT,
|
memberId: DataTypes.TEXT,
|
||||||
resourceId: DataTypes.TEXT,
|
oldResourceId: DataTypes.TEXT,
|
||||||
|
newResourceId: DataTypes.TEXT,
|
||||||
oldBookingStart: DataTypes.DATE,
|
oldBookingStart: DataTypes.DATE,
|
||||||
oldBookingEnd: DataTypes.DATE,
|
oldBookingEnd: DataTypes.DATE,
|
||||||
newBookingStart: DataTypes.DATE,
|
newBookingStart: DataTypes.DATE,
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ const bulkWriteBookingChangeIncidents = (incidents) => {
|
|||||||
|
|
||||||
const chargeBookingChanges = (changes) => {
|
const chargeBookingChanges = (changes) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
console.log(changes);
|
||||||
if (Array.isArray(changes)){
|
if (Array.isArray(changes)){
|
||||||
const incidents = [];
|
const incidents = [];
|
||||||
const errors = [];
|
const errors = [];
|
||||||
changes.forEach((change) => {
|
changes.forEach((change) => {
|
||||||
const { oldReservation, newReservation } = change;
|
const { oldReservation, newReservation } = change;
|
||||||
if (oldReservation && newReservation){
|
if (oldReservation && newReservation){
|
||||||
|
const oldResourceId = oldReservation.resourceId;
|
||||||
const oldStart = oldReservation.start ? moment.utc(oldReservation.start) : null;
|
const oldStart = oldReservation.start ? moment.utc(oldReservation.start) : null;
|
||||||
const oldEnd = oldReservation.end ? moment.utc(oldReservation.end) : null;
|
const oldEnd = oldReservation.end ? moment.utc(oldReservation.end) : null;
|
||||||
|
|
||||||
@@ -56,14 +58,14 @@ const chargeBookingChanges = (changes) => {
|
|||||||
// Check if member shortened the reservation
|
// Check if member shortened the reservation
|
||||||
|
|
||||||
if (newReservationLength < oldReservationLength){
|
if (newReservationLength < oldReservationLength){
|
||||||
|
|
||||||
const differenceInLength = oldReservationLength - newReservationLength;
|
const differenceInLength = oldReservationLength - newReservationLength;
|
||||||
const chargeFee = differenceInLength*hourlyRate*BOOKING_CHANGE_PERCENTAGE_CHARGE/100;
|
const chargeFee = differenceInLength*hourlyRate*BOOKING_CHANGE_PERCENTAGE_CHARGE/100;
|
||||||
|
|
||||||
const incident = {
|
const incident = {
|
||||||
reservationId,
|
reservationId,
|
||||||
memberId,
|
memberId,
|
||||||
resourceId,
|
oldResourceId: oldResourceId || newReservation.resourceId,
|
||||||
|
newResourceId: newReservation.resourceId,
|
||||||
oldBookingStart: oldReservation.start,
|
oldBookingStart: oldReservation.start,
|
||||||
oldBookingEnd: oldReservation.end,
|
oldBookingEnd: oldReservation.end,
|
||||||
newBookingStart: newReservation.start,
|
newBookingStart: newReservation.start,
|
||||||
@@ -82,7 +84,8 @@ const chargeBookingChanges = (changes) => {
|
|||||||
const incident = {
|
const incident = {
|
||||||
reservationId,
|
reservationId,
|
||||||
memberId,
|
memberId,
|
||||||
resourceId,
|
oldResourceId: oldResourceId || newReservation.resourceId,
|
||||||
|
newResourceId: newReservation.resourceId,
|
||||||
oldBookingStart: oldReservation.start,
|
oldBookingStart: oldReservation.start,
|
||||||
oldBookingEnd: oldReservation.end,
|
oldBookingEnd: oldReservation.end,
|
||||||
newBookingStart: newReservation.start,
|
newBookingStart: newReservation.start,
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ const bulkWriteReservationsWithChangesTracking = (reservations) => {
|
|||||||
const changedKeys = instance.changed();
|
const changedKeys = instance.changed();
|
||||||
const previous = instance.previous();
|
const previous = instance.previous();
|
||||||
|
|
||||||
const lookupKeys = ['start', 'end'];
|
const lookupKeys = ['start', 'end', 'resourceId'];
|
||||||
|
|
||||||
let realChange = false;
|
let realChange = false;
|
||||||
lookupKeys.forEach((key) => {
|
lookupKeys.forEach((key) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user