fix door lock charges - unlocked incident
This commit is contained in:
@@ -18,6 +18,7 @@ const {
|
||||
|
||||
const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { getMappingsFromDatabase } = require('../officeRnD/resources');
|
||||
const { getFirstReservationInBlock } = require('../officeRnD/bookings');
|
||||
|
||||
const extractMappingFromFileName = (fileName) => {
|
||||
const contentBetweenBracketsRegex = /\[(.*?)\]/;
|
||||
@@ -360,9 +361,48 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getLastEntryForReservation = (reservation) => {
|
||||
return new Promise ((resolve, reject) => {
|
||||
getFirstReservationInBlock(reservation)
|
||||
.then((firstReservationInBlock) => {
|
||||
const { memberId, resourceId } = reservation;
|
||||
let fromTimestamp = reservation.start;
|
||||
const toTimestamp = reservation.end;
|
||||
if (firstReservationInBlock){
|
||||
fromTimestamp = firstReservationInBlock.start;
|
||||
}
|
||||
|
||||
const filters = {
|
||||
memberId,
|
||||
resourceId,
|
||||
timestamp: {
|
||||
[Op.and]: [
|
||||
{[Op.gte]: fromTimestamp},
|
||||
{[Op.lte]: toTimestamp}
|
||||
]
|
||||
},
|
||||
};
|
||||
|
||||
const order = [['timestamp', 'DESC']];
|
||||
|
||||
db.doorLockEvent.findAll({where: filters, order})
|
||||
.then((entries) => {
|
||||
if (entries && entries.length > 0){
|
||||
resolve(entries[0]);
|
||||
} else {
|
||||
resolve (undefined);
|
||||
}
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
parseDoorLockDataFile,
|
||||
writeDoorLockEvent,
|
||||
getUnlockEntryForReservation,
|
||||
getLockEntryForReservation,
|
||||
getLastEntryForReservation,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user