Bug fix for bookings

This commit is contained in:
Senad Uka
2019-07-19 22:25:22 +02:00
parent 4389aaa8da
commit 0c92febe52
4 changed files with 27 additions and 17 deletions

View File

@@ -3,7 +3,7 @@
const moment = require('moment-timezone');
const db = require('../../models/index');
const { UI_TIMEZONE, BOOKING_CHANGE_PERCENTAGE_CHARGE, incidentType } = require('../../constants/constants');
const { UI_TIMEZONE, BOOKING_CHANGE_PERCENTAGE_CHARGE, ALLOWED_BOOKING_CANCELLATION_TIME, incidentType } = require('../../constants/constants');
const bulkWriteBookingChangeIncidents = (incidents) => {
return new Promise((resolve, reject) => {
@@ -33,9 +33,10 @@ const chargeBookingChanges = (changes) => {
const newStart = newReservation.start ? moment.utc(newReservation.start) : null;
const newEnd = newReservation.end ? moment.utc(newReservation.end) : null;
const reservationCreationTimestamp = newReservation.createdAt ? moment.utc(newReservation.createdAt) : null;
const reservationTimezone = newReservation.timezone ? newReservation.timezone : UI_TIMEZONE;
const reservationHourlyRate = oldReservation.hourlyRate ? oldReservation.hourlyRate : undefined;
const reservationHourlyRate = oldReservation.hourlyRate ? oldReservation.hourlyRate : newReservation.hourlyRate;
const canceled = newReservation.canceled;
if (oldStart && oldEnd && newStart && newEnd && reservationHourlyRate){
@@ -96,21 +97,25 @@ const chargeBookingChanges = (changes) => {
incidents.push(incident);
}
}else{
const chargeFee = 2 * reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
const incident = {
reservationId,
memberId,
oldResourceId: oldResourceId || resourceId,
newResourceId: null,
oldBookingStart: oldReservation.start,
oldBookingEnd: oldReservation.end,
newBookingStart: null,
newBookingEnd: null,
incidentType: incidentType.BOOKING_CANCELED_LATE,
chargeFee,
};
const differenceFromCreation = reservationCreationTimestamp.diff(moment.utc(), 'minutes');
incidents.push(incident);
if (differenceFromCreation > ALLOWED_BOOKING_CANCELLATION_TIME){
const chargeFee = 2 * reservationHourlyRate * oldReservationLength * BOOKING_CHANGE_PERCENTAGE_CHARGE / 100;
const incident = {
reservationId,
memberId,
oldResourceId: oldResourceId || resourceId,
newResourceId: null,
oldBookingStart: oldReservation.start,
oldBookingEnd: oldReservation.end,
newBookingStart: null,
newBookingEnd: null,
incidentType: incidentType.BOOKING_CANCELED_LATE,
chargeFee,
};
incidents.push(incident);
}
}
}
}