do not charge cancellation under 30 minutes of creation

This commit is contained in:
Bilal Catic
2019-07-19 12:47:16 +02:00
parent ef40483c22
commit 00988b0dac
3 changed files with 25 additions and 15 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,6 +33,7 @@ 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 : newReservation.hourlyRate;
@@ -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);
}
}
}
}