fix door lock charges

This commit is contained in:
Bilal Catic
2019-07-03 11:50:23 +02:00
parent fc4d374e23
commit 2b492025fb
2 changed files with 23 additions and 34 deletions

View File

@@ -190,10 +190,16 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
const attributes = ['memberName', 'event', 'timestamp', 'resourceId'];
const fromTimestamp = previousReservation && previousReservation.end ?
previousReservation.end : moment.utc(reservation.start).tz(UI_TIMEZONE).startOf('Day').toISOString();
const previousReservationEndMoment = previousReservation && previousReservation.end ?
moment.utc(previousReservation.end) : null;
const reservationStartMoment = moment.utc(reservation.start);
const fromTimestamp = previousReservationEndMoment && previousReservationEndMoment.tz(UI_TIMEZONE).isSame(reservationStartMoment.tz(UI_TIMEZONE), 'day') ?
previousReservation.end : reservationStartMoment.tz(UI_TIMEZONE).startOf('day').toISOString();
const toTimestamp = reservation.end;
const filters = {
memberId,
timestamp: {
@@ -217,21 +223,8 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
let pairedLockEntry = null;
let eventFound = false;
// console.log('\r\n=?== SEARCH UNLOCK ==');
// console.log('ReservatioN : ', reservation.start);
const entriesBeforeReservationStart = entries.filter((entry) => moment.utc(entry.timestamp).isBefore(reservation.start));
// console.log('After end : ');
/*console.log(entriesBeforeReservationStart.map(e => {
return {
timestamp: e.timestamp,
event: e.event,
}
}));
*/
entriesBeforeReservationStart.forEach((entry) => {
if (!eventFound) {
if (entry.event === doorLockEvents.USER_UNLOCKED) {
@@ -250,35 +243,21 @@ const getUnlockEntryForReservation = (reservation, previousReservation) => {
});
if (eventFound){
// console.log('FOUND : ', candidateUnlockEntry.timestamp, candidateUnlockEntry.event);
resolve(candidateUnlockEntry);
} else {
// console.log('NOT FOUND IN FIRST ROUND');
candidateUnlockEntry = null;
const numberOfEntriesLeft = entries.length - entriesBeforeReservationStart.length;
const entriesAfterReservationStart = entries.slice(0, numberOfEntriesLeft);
// console.log('Entries in reservation time : ');
/*console.log(entriesAfterReservationStart.map(e => {
return {
timestamp: e.timestamp,
event: e.event,
}
}));
*/
entriesAfterReservationStart.forEach((entry) => {
if (!eventFound) {
if (entry.event === doorLockEvents.USER_UNLOCKED) {
//console.log('FOUND : ', entry.timestamp, entry.event);
eventFound = true;
candidateUnlockEntry = entry;
}
}
});
//console.log('===??==');
resolve(candidateUnlockEntry);
}
})
@@ -292,9 +271,13 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
const attributes = ['memberName', 'event', 'timestamp'];
const nextReservationStartMoment = nextReservation && nextReservation.start ?
moment.utc(nextReservation.start) : null;
const reservationStartMoment = moment.utc(reservation.start);
const fromTimestamp = reservation.start;
const toTimestamp = nextReservation && nextReservation.start ?
nextReservation.start : moment.utc(reservation.start).tz(UI_TIMEZONE).endOf('Day').toISOString();
const toTimestamp = nextReservationStartMoment && nextReservationStartMoment.tz(UI_TIMEZONE).isSame(reservationStartMoment.tz(UI_TIMEZONE), 'day') ?
nextReservation.start : reservationStartMoment.tz(UI_TIMEZONE).endOf('day').toISOString();
const filters = {
memberId,
@@ -361,6 +344,10 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
});
};
const getEntriesBetween = (reservation, previousReservation) => {
};
const getLastEntryForReservation = (reservation) => {
return new Promise ((resolve, reject) => {
getFirstReservationInBlock(reservation)
@@ -404,5 +391,6 @@ module.exports = {
writeDoorLockEvent,
getUnlockEntryForReservation,
getLockEntryForReservation,
getEntriesBetween,
getLastEntryForReservation,
};