add debugging logs
This commit is contained in:
@@ -533,92 +533,123 @@ const getIncidentData = (reservation) => {
|
||||
|
||||
getEntriesBetween(fromTimestamp, toTimestamp, resourceId)
|
||||
.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--------------------');
|
||||
// }
|
||||
|
||||
let pairUnlockEntry = null;
|
||||
let pairLockEntry = null;
|
||||
|
||||
//Inspect all entries and insert detected incidents
|
||||
entriesBetween.forEach((entry) => {
|
||||
if (entry && entry.event){
|
||||
switch(entry.event){
|
||||
case doorLockEvents.USER_UNLOCKED:
|
||||
if (!pairUnlockEntry){
|
||||
pairUnlockEntry = entry;
|
||||
}else{
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
// console.log('\tEvent : ', entry.event);
|
||||
// console.log('\tEvent : ', entry.timestamp ? moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM, HH:mm') : '-');
|
||||
if (entry && entry.event){
|
||||
switch(entry.event){
|
||||
case doorLockEvents.USER_UNLOCKED:
|
||||
if (!pairUnlockEntry){
|
||||
pairUnlockEntry = entry;
|
||||
}else{
|
||||
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 = entry;
|
||||
}
|
||||
break;
|
||||
case doorLockEvents.USER_LOCKED:
|
||||
if (pairUnlockEntry && !pairLockEntry){
|
||||
pairLockEntry = entry;
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
||||
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
||||
|
||||
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
|
||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
||||
if (timeIntervalsToCharge > 0){
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
lockTimestamp: pairLockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||
timeIntervalsToCharge,
|
||||
totalChargeFee,
|
||||
});
|
||||
|
||||
pairLockEntry = null;
|
||||
pairUnlockEntry = entry;
|
||||
}
|
||||
break;
|
||||
case doorLockEvents.USER_LOCKED:
|
||||
if (pairUnlockEntry && !pairLockEntry){
|
||||
pairLockEntry = entry;
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
const unlockMoment = moment.utc(pairUnlockEntry.timestamp);
|
||||
const lockMoment = moment.utc(pairLockEntry.timestamp);
|
||||
}else{
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
|
||||
if (lockMoment.tz(UI_TIMEZONE).isSame(unlockMoment.tz(UI_TIMEZONE), 'day')){
|
||||
const timeDifference = lockMoment.diff(unlockMoment, 'minutes');
|
||||
const timeIntervalsToCharge = Math.floor(timeDifference / UNSCHEDULED_TIME_RESOLUTION);
|
||||
const totalChargeFee = timeIntervalsToCharge * UNSCHEDULED_CHARGE_PRICE;
|
||||
if (timeIntervalsToCharge > 0){
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNSCHEDULED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
lockTimestamp: pairLockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
chargePrice: UNSCHEDULED_CHARGE_PRICE,
|
||||
timeIntervalsToCharge,
|
||||
totalChargeFee,
|
||||
});
|
||||
}
|
||||
}else{
|
||||
const emptyReservation = {
|
||||
reservationId: null,
|
||||
start: null,
|
||||
end: null,
|
||||
};
|
||||
incidents.push({
|
||||
incidentType: incidentType.UNLOCKED_INCIDENT_STANDALONE,
|
||||
reservation: emptyReservation,
|
||||
unlockTimestamp: pairUnlockEntry.timestamp,
|
||||
memberId: pairUnlockEntry.memberId,
|
||||
resourceId,
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
pairUnlockEntry = null;
|
||||
pairLockEntry = null;
|
||||
}else{
|
||||
if (!pairUnlockEntry){
|
||||
pairLockEntry = entry;
|
||||
//Only lock entry, ignore now
|
||||
}
|
||||
pairLockEntry = null;
|
||||
pairUnlockEntry = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Now wait also for "forgotToLockAsyncCheck" to finish
|
||||
|
||||
Reference in New Issue
Block a user