fix how unlocked and unscheduled incidents are applied

This commit is contained in:
Bilal Catic
2019-12-13 18:36:39 +01:00
parent a604687c61
commit 501b8cf629

View File

@@ -587,37 +587,13 @@ const getIncidentData = (reservation) => {
//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')) {
// console.log('\r\n\r\n==== ANALYSE RESERVATION [GET INCIDENT DATA] ==== ');
// console.log('\tStart : ', reservationMoment.format('DD.MM, HH:mm'));
// console.log('\tEnd : ', moment.tz(currentReservation.end, currentReservation.timezone).format('DD.MM, HH:mm'));
// console.log('\t----------------------------------');
// console.log('\tFirst previous reservation : is back to back [', previousReservationIsBackToBack ? 'T' : 'F', ']');
// 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 : is back to back [', nextReservationIsBackToBack ? 'T' : 'F', ']');
// 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--------------------');
//
// console.log('\tFrom timestamp : ', fromTimestamp ? moment.tz(fromTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
// console.log('\tTo timestamp : ', toTimestamp ? moment.tz(toTimestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
// console.log('\t--------------------');
// }
}
//Now wait for "forgotToLockAsyncCheck", and possible "getEntriesBetween" to finish
Promise.all([forgotToLockAsyncCheck, getEntriesAsyncCheck])
.then((asyncActionResults) => {
const entriesBetween = asyncActionResults[1];
if (Array.isArray(entriesBetween)){
let pairUnlockEntry = null;
let pairLockEntry = null;
@@ -650,7 +626,18 @@ const getIncidentData = (reservation) => {
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
const lockMoment = moment.utc(pairLockEntry.timestamp);
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
const entriesOnSameDay = lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day');
const sameMember = pairUnlockEntry.memberId === pairLockEntry.memberId;
if ((entriesOnSameDay && !sameMember) || (!entriesOnSameDay)){
incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
reservation: emptyReservation,
unlockTimestamp: pairUnlockEntry.timestamp,
memberId: pairUnlockEntry.memberId,
resourceId,
});
}else if (entriesOnSameDay && sameMember){
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
@@ -667,23 +654,10 @@ const getIncidentData = (reservation) => {
totalChargeFee,
});
}
}else{
incidents.push({
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
reservation: emptyReservation,
unlockTimestamp: pairUnlockEntry.timestamp,
memberId: pairUnlockEntry.memberId,
resourceId,
});
}
pairUnlockEntry = null;
pairLockEntry = null;
}else{
if (!pairUnlockEntry){
pairLockEntry = entry;
//Only lock entry, ignore now
}
pairLockEntry = null;
pairUnlockEntry = null;
}
@@ -703,21 +677,7 @@ const getIncidentData = (reservation) => {
pairLockEntry = null;
pairUnlockEntry = null;
}
//Now wait also for "forgotToLockAsyncCheck" to finish
// 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));