allow first time segment length for unscheduled use to be configurable

This commit is contained in:
Bilal Catic
2019-11-22 20:22:44 +01:00
parent 1436f0fdab
commit 93d46c231e
4 changed files with 83 additions and 3 deletions

View File

@@ -109,6 +109,7 @@ const UI_TIMEZONE = process.env.UI_TIMEZONE || 'America/Los_Angeles';
const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
const MAX_BACK_TO_BACK_DIFFERENCE = parseInt(process.env.MAX_BACK_TO_BACK_DIFFERENCE) || 0;
const UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH = parseInt(process.env.UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH) || 7;
const UNSCHEDULED_TIME_RESOLUTION = parseInt(process.env.UNSCHEDULED_USE_TIME_RESOLUTION) || 5;
const UNSCHEDULED_CHARGE_PRICE = parseFloat(process.env.UNSCHEDULED_USE_CHARGE_PRICE) || 5;
@@ -154,6 +155,7 @@ module.exports = {
UI_TIMEZONE,
DEFAULT_DATE_FORMAT,
MAX_BACK_TO_BACK_DIFFERENCE,
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH,
UNSCHEDULED_TIME_RESOLUTION,
UNSCHEDULED_CHARGE_PRICE,
BOOKING_CHANGE_PERCENTAGE_CHARGE,

View File

@@ -8,6 +8,7 @@ EARLIEST_UNLOCK=Time in minutes
UI_TIMEZONE=Timezone for user interface | https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | example : America/Los_Angeles
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH=Time in minutes when first unscheduled use charge will be applied
UNSCHEDULED_USE_TIME_RESOLUTION=Time in minutes
UNSCHEDULED_USE_CHARGE_PRICE=Charge price

View File

@@ -205,6 +205,14 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
const toTimestamp = reservation.end;
// if (reservation.memberId === '5ce785af422bdd00967fb781') {
// console.log('=======================');
// console.log('\tStart : ', moment.tz(reservation.start, reservation.timezone).format('DD.MM, HH:mm'));
// console.log('\tEnd : ', moment.tz(reservation.end, reservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t----------------------------------');
// console.log('\tFrom time : ', fromTimestamp);
// console.log('\tTo time : ', toTimestamp);
// }
const filters = {
memberId,

View File

@@ -10,6 +10,7 @@ const {
unlockedIncidentLevelsPrices,
UNSCHEDULED_CHARGE_PRICE,
MAX_BACK_TO_BACK_DIFFERENCE,
UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH,
UNSCHEDULED_TIME_RESOLUTION,
UI_TIMEZONE
} = require('../../constants/constants');
@@ -252,7 +253,11 @@ const analyseReservation = (reservation) => {
const unlockTime = moment.utc(unlockEntry.timestamp);
timeDifferenceFromUnlockEntry = currentReservationStart.diff(unlockTime, 'minutes');
}
const timeIntervalsToChargeBefore = Math.floor(timeDifferenceFromUnlockEntry / UNSCHEDULED_TIME_RESOLUTION);
let timeIntervalsToChargeBefore = Math.floor(timeDifferenceFromUnlockEntry / UNSCHEDULED_TIME_RESOLUTION);
if (timeDifferenceFromUnlockEntry < UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH){
timeIntervalsToChargeBefore = 0;
}
const totalChargeFeeBefore = timeIntervalsToChargeBefore * UNSCHEDULED_CHARGE_PRICE;
const chargeBefore = totalChargeFeeBefore > 0;
@@ -261,10 +266,54 @@ const analyseReservation = (reservation) => {
const lockTime = moment.utc(lockEntry.timestamp);
timeDifferenceFromLockEntry = lockTime.diff(currentReservationEnd, 'minutes');
}
const timeIntervalsToChargeAfter = Math.floor(timeDifferenceFromLockEntry / UNSCHEDULED_TIME_RESOLUTION);
let timeIntervalsToChargeAfter = Math.floor(timeDifferenceFromLockEntry / UNSCHEDULED_TIME_RESOLUTION);
if (timeDifferenceFromLockEntry < UNSCHEDULED_USE_INITIAL_TIME_SEGMENT_LENGTH){
timeIntervalsToChargeAfter = 0;
}
const totalChargeFeeAfter = timeIntervalsToChargeAfter * UNSCHEDULED_CHARGE_PRICE;
const chargeAfter = totalChargeFeeAfter > 0;
// if (reservation.memberId === '5ce785af422bdd00967fb781') {
// console.log('\r\n\r\n==== ANALYSE RESERVATION ==== ');
// console.log('\tStart : ', moment.tz(reservation.start, reservation.timezone).format('DD.MM, HH:mm'));
// console.log('\tEnd : ', moment.tz(reservation.end, reservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t----------------------------------');
// console.log('\tFirst previous reservation : ');
// if (previousReservation) {
// console.log('\t\tStart : ', moment.tz(previousReservation.start, previousReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t\tEnd : ', moment.tz(previousReservation.end, previousReservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\t\tNO PREVIOUS RESERVATION');
// }
//
// console.log('\tFirst next reservation : ');
// if (nextReservation) {
// console.log('\t\tStart : ', moment.tz(nextReservation.start, nextReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t\tEnd : ', moment.tz(nextReservation.end, nextReservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\t\tNO NEXT RESERVATION');
// }
// console.log('\t----------------------------------');
// if (unlockEntry) {
// console.log('\tUnlock entry : ', moment.tz(unlockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\tUnlock entry : NO UNLOCK ENTRY');
// }
// if (lockEntry) {
// console.log('\tLock entry : ', moment.tz(lockEntry.timestamp, reservation.timezone).format('DD.MM, HH:mm'));
// } else {
// console.log('\tLock entry : NO LOCK ENTRY');
// }
//
// console.log('\t----------------------------------');
// console.log('\tTime before : ');
// console.log('\t\tOriginal : ', timeDifferenceFromUnlockEntry);
// console.log('\t\tModified : ', timeIntervalsToChargeBefore);
// console.log('\tTime after : ');
// console.log('\t\tOriginal : ', timeDifferenceFromLockEntry);
// console.log('\t\tModified : ', timeIntervalsToChargeAfter);
// }
const result = {
currentReservation: reservation,
previousReservation,
@@ -445,7 +494,12 @@ const getIncidentData = (reservation) => {
.catch((error) => reject(error)));
// 1. Check if member entered before reservation start time
// console.log('\r\n\r\nChecking if member entered before reservation start time :');
// console.log('\tunlockEntry : ', unlockEntry && unlockEntry.timestamp ? unlockEntry.timestamp : 'NO UNLOCK ENTRY');
// console.log('\tCharge before : ', chargeBefore);
// console.log('\tThere is prev. res : ', previousReservationIsBackToBack);
if (unlockEntry && chargeBefore && !previousReservationIsBackToBack) {
// console.log('\tIncident : YES');
incidents.push({
incidentType: incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
reservation,
@@ -457,10 +511,17 @@ const getIncidentData = (reservation) => {
timeIntervalsToCharge: timeIntervalsToChargeBefore,
totalChargeFee: totalChargeFeeBefore,
});
}else{
// console.log('\tIncident : NO');
}
// 2. Check if member left after reservation end time
// console.log('\r\n\r\nChecking if member left after reservation end time :');
// console.log('\tlockEntry : ', lockEntry && lockEntry.timestamp ? lockEntry.timestamp : 'NO LOCK ENTRY');
// console.log('\tCharge after : ', chargeAfter);
// console.log('\tThere is res after : ', nextReservationIsBackToBack);
if (lockEntry && chargeAfter && !nextReservationIsBackToBack) {
// console.log('\tIncident : YES');
incidents.push({
incidentType: incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
reservation,
@@ -472,9 +533,16 @@ const getIncidentData = (reservation) => {
timeIntervalsToCharge: timeIntervalsToChargeAfter,
totalChargeFee: totalChargeFeeAfter,
});
}else{
// console.log('\tIncident : NO');
}
// 3. Check if member forgot to lock the door
// console.log('\r\n\r\nChecking if member left unlocked door :');
// console.log('\tunlockEntry : ', unlockEntry && unlockEntry.timestamp ? unlockEntry.timestamp : 'NO UNLOCK ENTRY');
// console.log('\tlockEntry : ', lockEntry && lockEntry.timestamp ? lockEntry.timestamp : 'NO LOCK ENTRY');
// console.log('\tThere is res before: ', previousReservationIsBackToBack);
// console.log('\tThere is res after : ', nextReservationIsBackToBack);
if (!lockEntry && !nextReservationIsBackToBack){
const emptyReservation = {
reservationId: null,
@@ -483,7 +551,7 @@ const getIncidentData = (reservation) => {
};
if (unlockEntry){
// console.log('\tIncident : YES [#1]');
incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
unlockTimestamp: unlockEntry.timestamp,
@@ -506,6 +574,7 @@ const getIncidentData = (reservation) => {
getLastEntryForReservation(reservation)
.then((lastEntry) => {
if (lastEntry && lastEntry.event === doorLockEvents.USER_UNLOCKED){
// console.log('\tIncident : YES [#2]');
incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
unlockTimestamp: lastEntry.timestamp,