Fix undetected unschedule use in brake between bookings #80

Merged
bilal.catic merged 3 commits from fix-undetected-unschedule-use-in-brake-between-bookings into master 2019-12-26 02:34:16 +01:00
Showing only changes of commit c1f3f42368 - Show all commits

View File

@@ -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));