fix how unlocked incident fees are applied
This commit is contained in:
@@ -238,7 +238,7 @@ const analyseReservation = (reservation) => {
|
||||
const previousReservationEnd = moment.utc(previousReservation.end);
|
||||
timeDifferenceFromPreviousReservation = currentReservationStart.diff(previousReservationEnd, 'minutes');
|
||||
}
|
||||
const previousReservationIsBackToBack = timeDifferenceFromPreviousReservation < MAX_BACK_TO_BACK_DIFFERENCE;
|
||||
const previousReservationIsBackToBack = timeDifferenceFromPreviousReservation <= MAX_BACK_TO_BACK_DIFFERENCE;
|
||||
|
||||
|
||||
let timeDifferenceBeforeNextReservation = MAX_BACK_TO_BACK_DIFFERENCE + 100;
|
||||
@@ -246,7 +246,7 @@ const analyseReservation = (reservation) => {
|
||||
const nextReservationStart = moment.utc(nextReservation.start);
|
||||
timeDifferenceBeforeNextReservation = nextReservationStart.diff(currentReservationEnd, 'minutes');
|
||||
}
|
||||
const nextReservationIsBackToBack = timeDifferenceBeforeNextReservation < MAX_BACK_TO_BACK_DIFFERENCE;
|
||||
const nextReservationIsBackToBack = timeDifferenceBeforeNextReservation <= MAX_BACK_TO_BACK_DIFFERENCE;
|
||||
|
||||
let timeDifferenceFromUnlockEntry = 0;
|
||||
if (unlockEntry) {
|
||||
@@ -406,12 +406,16 @@ const getIncidentData = (reservation) => {
|
||||
//**********************
|
||||
|
||||
// 1. Check if member entered before reservation start time
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// 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) {
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : YES');
|
||||
// }
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
|
||||
reservation,
|
||||
@@ -424,16 +428,22 @@ const getIncidentData = (reservation) => {
|
||||
totalChargeFee: totalChargeFeeBefore,
|
||||
});
|
||||
}else{
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : NO');
|
||||
// }
|
||||
}
|
||||
|
||||
// 2. Check if member left after reservation end time
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// 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) {
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : YES');
|
||||
// }
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_AFTER_RESERVATION,
|
||||
reservation,
|
||||
@@ -446,15 +456,19 @@ const getIncidentData = (reservation) => {
|
||||
totalChargeFee: totalChargeFeeAfter,
|
||||
});
|
||||
}else{
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : NO');
|
||||
// }
|
||||
}
|
||||
|
||||
// 3. Check if member forgot to lock the door
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// 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);
|
||||
// }
|
||||
let forgotToLockAsyncCheck;
|
||||
if (!lockEntry && !nextReservationIsBackToBack){
|
||||
const emptyReservation = {
|
||||
@@ -464,7 +478,9 @@ const getIncidentData = (reservation) => {
|
||||
};
|
||||
|
||||
if (unlockEntry){
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : YES [#1]');
|
||||
// }
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||
unlockTimestamp: unlockEntry.timestamp,
|
||||
@@ -488,7 +504,9 @@ const getIncidentData = (reservation) => {
|
||||
forgotToLockAsyncCheck
|
||||
.then((lastEntry) => {
|
||||
if (lastEntry && lastEntry.event === doorLockEvents.USER_UNLOCKED){
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-12-01 00:00:16+00')) {
|
||||
// console.log('\tIncident : YES [#2]');
|
||||
// }
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
|
||||
unlockTimestamp: lastEntry.timestamp,
|
||||
@@ -531,7 +549,13 @@ const getIncidentData = (reservation) => {
|
||||
unlockEntry.timestamp : reservation.start;
|
||||
}
|
||||
|
||||
getEntriesBetween(fromTimestamp, toTimestamp, resourceId)
|
||||
// Let's skip this if previous reservation is back-to-back
|
||||
let getEntriesAsyncCheck;
|
||||
if (previousReservation && previousReservationIsBackToBack){
|
||||
//Skip
|
||||
}else{
|
||||
getEntriesAsyncCheck = getEntriesBetween(fromTimestamp, toTimestamp, resourceId);
|
||||
getEntriesAsyncCheck
|
||||
.then((entriesBetween) => {
|
||||
// const reservationMoment = moment.tz(currentReservation.start, currentReservation.timezone);
|
||||
// if (currentReservation.memberId === '5ce785af422bdd00967fb781' && reservationMoment.isAfter('2019-11-23 00:00:16+00')) {
|
||||
@@ -651,16 +675,42 @@ const getIncidentData = (reservation) => {
|
||||
}
|
||||
});
|
||||
|
||||
if (pairUnlockEntry){
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
});
|
||||
|
||||
pairLockEntry = null;
|
||||
pairUnlockEntry = null;
|
||||
}
|
||||
|
||||
|
||||
//Now wait also for "forgotToLockAsyncCheck" to finish
|
||||
Promise.all([forgotToLockAsyncCheck])
|
||||
// Promise.all([forgotToLockAsyncCheck])
|
||||
// .then(() => {
|
||||
// resolve(incidents);
|
||||
// })
|
||||
// .catch(error => reject(error));
|
||||
})
|
||||
.catch((error) => reject(error))
|
||||
}
|
||||
|
||||
//Now wait for "forgotToLockAsyncCheck", and possible "getEntriesBetween" to finish
|
||||
Promise.all([forgotToLockAsyncCheck, getEntriesAsyncCheck])
|
||||
.then(() => {
|
||||
resolve(incidents);
|
||||
})
|
||||
.catch(error => reject(error));
|
||||
|
||||
})
|
||||
.catch((error) => reject(error))
|
||||
})
|
||||
.catch(error => reject(error));
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user