add method for finding last reservation in a block
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user