From 00988b0dac5daa54f95d039412b2fcf8c3d493ff Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Fri, 19 Jul 2019 12:47:16 +0200 Subject: [PATCH] do not charge cancellation under 30 minutes of creation --- constants/constants.js | 3 ++ environment.env | 2 ++ services/integration/bookingChangeCharges.js | 35 +++++++++++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/constants/constants.js b/constants/constants.js index 03443e5..d339663 100644 --- a/constants/constants.js +++ b/constants/constants.js @@ -81,6 +81,8 @@ const UNSCHEDULED_CHARGE_PRICE = parseFloat(process.env.UNSCHEDULED_USE_CHARGE_P const BOOKING_CHANGE_PERCENTAGE_CHARGE = parseInt(process.env.BOOKING_CHANGE_PERCENTAGE_CHARGE) || 100; +const ALLOWED_BOOKING_CANCELLATION_TIME= parseInt(process.env.ALLOWED_BOOKING_CANCELLATION_TIME) || 30; + module.exports = { VALID_CSV_HEADERS, USER_ENTRY_EVENT, @@ -98,4 +100,5 @@ module.exports = { UNSCHEDULED_TIME_RESOLUTION, UNSCHEDULED_CHARGE_PRICE, BOOKING_CHANGE_PERCENTAGE_CHARGE, + ALLOWED_BOOKING_CANCELLATION_TIME, }; diff --git a/environment.env b/environment.env index 1ea3b01..b4f3c76 100644 --- a/environment.env +++ b/environment.env @@ -20,3 +20,5 @@ UNLOCK_5=Price for unlocked door, sixth month UNLOCK_STREAK_REPAIR_AFTER=Number of months without incidents to reset user incident level BOOKING_CHANGE_PERCENTAGE_CHARGE=Percentage of hourly reate to apply for cancellation-like charges + +ALLOWED_BOOKING_CANCELLATION_TIME=Time from creation (in minutes) in which cancellation is not charged diff --git a/services/integration/bookingChangeCharges.js b/services/integration/bookingChangeCharges.js index db0c961..cbe26c4 100644 --- a/services/integration/bookingChangeCharges.js +++ b/services/integration/bookingChangeCharges.js @@ -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); + } } } }