match unlock entry before first reservation in a block
This commit is contained in:
@@ -19,7 +19,7 @@ const {
|
||||
|
||||
const { fetchAllMembers } = require('../officeRnD/members');
|
||||
const { getMappingsFromDatabase } = require('../officeRnD/resources');
|
||||
const { getFirstReservationInBlock } = require('../officeRnD/bookings');
|
||||
const { getFirstReservationInBlock, getFirstPreviousBooking } = require('../officeRnD/bookings');
|
||||
|
||||
const extractMappingFromFileName = (fileName) => {
|
||||
const contentBetweenBracketsRegex = /\[(.*?)\]/;
|
||||
@@ -425,11 +425,25 @@ const getLastEntryForReservation = (reservation) => {
|
||||
const order = [['timestamp', 'DESC']];
|
||||
|
||||
db.doorLockEvent.findAll({where: filters, order})
|
||||
.then((entries) => {
|
||||
.then(async(entries) => {
|
||||
if (entries && entries.length > 0){
|
||||
resolve(entries[0]);
|
||||
} else {
|
||||
resolve (undefined);
|
||||
//No entry found in this block of reservations, now check if there is unlock entry for the first reservation in block, before reservation start time
|
||||
|
||||
try {
|
||||
const firstPreviousBookingBeforeFirstInBlock = await getFirstPreviousBooking(firstReservationInBlock);
|
||||
const unlockEntryForFirstInBlock = await getUnlockEntryForReservation(firstReservationInBlock, firstPreviousBookingBeforeFirstInBlock);
|
||||
|
||||
if (unlockEntryForFirstInBlock){
|
||||
resolve(unlockEntryForFirstInBlock);
|
||||
}else{
|
||||
resolve(undefined);
|
||||
}
|
||||
|
||||
}catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
|
||||
Reference in New Issue
Block a user