add method for finding last reservation in a block

This commit is contained in:
Bilal Catic
2019-12-26 02:30:03 +01:00
parent c1f3f42368
commit 87d7193bb9

View File

@@ -244,6 +244,32 @@ const getFirstReservationInBlock = (reservation) => {
});
};
const getLastReservationInBlock = async (reservation) => {
const { resourceId, memberId, end } = reservation;
const toTimestamp = moment.utc(end).add(MAX_BACK_TO_BACK_DIFFERENCE).toISOString();
const fromTimestamp = end;
const filters = {
resourceId,
memberId,
start: {
[Op.and]: [
{[Op.gte]: fromTimestamp},
{[Op.lte]: toTimestamp}
]
}
};
const nextReservation = await db.bookingReservation.findOne({where: filters});
if (!nextReservation) {
return reservation;
} else {
return getLastReservationInBlock(nextReservation);
}
};
const writeBookingReservation = (bookingReservation) => {
const { reservationId, memberId, officeId, resourceId, start, end, timezone, canceled, hourlyRate } = bookingReservation;
const bookingReservationForDB = {
@@ -369,5 +395,6 @@ module.exports = {
getFirstNextBooking,
getFirstPreviousBooking,
getFirstReservationInBlock,
getLastReservationInBlock,
bulkWriteReservationsWithChangesTracking,
};