fix wrong entrance entry detection after reservation start

This commit is contained in:
Bilal Catic
2019-12-11 20:47:07 +01:00
parent f0b4a069e8
commit 3d7db8b156

View File

@@ -238,7 +238,25 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
const entriesBeforeReservationStart = entries.filter((entry) => moment.utc(entry.timestamp).isBefore(reservation.start));
// if (memberId === '5ce785af422bdd00967fb781') {
// console.log('Start : ', moment.tz(reservation.start, UI_TIMEZONE).format('DD.MM HH:mm'));
// console.log('End : ', moment.tz(reservation.end, UI_TIMEZONE).format('DD.MM HH:mm'));
// console.log('\tPrevious reservation ');
// console.log('\tStart : ', previousReservation ? moment.tz(previousReservation.start, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
// console.log('\tEnd : ', previousReservation ? moment.tz(previousReservation.end, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
// console.log('\t---------------------------');
// console.log('\tSearch for entries : ');
// console.log('\tFrom : ', fromTimestamp ? moment.tz(fromTimestamp, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
// console.log('\tTo : ', toTimestamp ? moment.tz(toTimestamp, UI_TIMEZONE).format('DD.MM HH:mm') : '-');
// console.log('\t---------------------------');
// console.log('\tEntries before reservation start : ');
// }
entriesBeforeReservationStart.forEach((entry) => {
// if (memberId === '5ce785af422bdd00967fb781') {
// console.log('\t', entry.event, '\t', moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM HH:mm'));
// }
if (!eventFound) {
if (entry.event === doorLockEvents.USER_UNLOCKED) {
if (pairedLockEntry) {
@@ -256,13 +274,25 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
});
if (eventFound){
// if (memberId === '5ce785af422bdd00967fb781') {
// console.log('\t=> FOUND UNLOCK ENTRY - NO NEED TO LOOK AFTER <=');
// }
resolve(candidateUnlockEntry);
} else {
candidateUnlockEntry = null;
const numberOfEntriesLeft = entries.length - entriesBeforeReservationStart.length;
const entriesAfterReservationStart = entries.slice(0, numberOfEntriesLeft);
const invertedEntriesAfterReservationStart = entriesAfterReservationStart.reverse();
// if (memberId === '5ce785af422bdd00967fb781') {
// console.log('\t-----------------------------');
// console.log('\tEntries after reservation start : ');
// }
invertedEntriesAfterReservationStart.forEach((entry) => {
// if (memberId === '5ce785af422bdd00967fb781') {
// console.log('\t', entry.event, '\t', moment.tz(entry.timestamp, UI_TIMEZONE).format('DD.MM HH:mm'));
// }
entriesAfterReservationStart.forEach((entry) => {
if (!eventFound) {
if (entry.event === doorLockEvents.USER_UNLOCKED) {
eventFound = true;