include unscheduled use between reservations

This commit is contained in:
Bilal Catic
2019-07-03 14:34:34 +02:00
parent 2b492025fb
commit 23b0924b5a
2 changed files with 143 additions and 10 deletions

View File

@@ -344,8 +344,33 @@ const getLockEntryForReservation = (reservation, nextReservation) => {
});
};
const getEntriesBetween = (reservation, previousReservation) => {
const getEntriesBetween = (fromTimestamp, toTimestamp, resourceId) => {
return new Promise((resolve, reject) => {
if (!fromTimestamp || !toTimestamp || !resourceId){
resolve([]);
}else {
const andTimestampFilters = [];
if (fromTimestamp){
andTimestampFilters.push({[Op.gt]: fromTimestamp});
}
if (toTimestamp){
andTimestampFilters.push({[Op.lt]: toTimestamp});
}
const filters = {
resourceId,
timestamp: {
[Op.and]: andTimestampFilters,
},
};
const order = [['timestamp', 'ASC']];
db.doorLockEvent.findAll({where: filters, order})
.then((results) => resolve(results))
.catch((error) => reject(error));
}
});
};
const getLastEntryForReservation = (reservation) => {