Merge branch 'main' into feature/booking-filters
This commit is contained in:
commit
53089686c5
|
@ -196,21 +196,32 @@ export async function getUserAvailability(
|
|||
// Take PER_DAY and turn it into day and PER_WEEK into week etc.
|
||||
const filter = limitKey.split("_")[1].toLocaleLowerCase() as "day" | "week" | "month" | "year";
|
||||
|
||||
let total = 0;
|
||||
|
||||
// Get all bookings that are within the filter period
|
||||
ourBookings.forEach((booking) => {
|
||||
const startDate = dayjs(booking.start).startOf(filter);
|
||||
// loop through all dates and check if we have reached the limit
|
||||
for (const date of dates) {
|
||||
let total = 0;
|
||||
const startDate = dayjs(date).startOf(filter);
|
||||
// this is parsed above with parseBookingLimit so we know it's safe.
|
||||
const endDate = dayjs(startDate).endOf(filter);
|
||||
const bookingEventTypeId = booking.source?.split("-")[1];
|
||||
if (dayjs(booking.start).isBetween(startDate, endDate)) total++;
|
||||
// Only check OUR booking that matches the current eventTypeId
|
||||
// we don't care about another event type in this case as we dont need to know their booking limits
|
||||
if (total >= limit && bookingEventTypeId === eventType?.id?.toString()) {
|
||||
bufferedBusyTimes.push({ start: startDate.toISOString(), end: endDate.toISOString() });
|
||||
const endDate = dayjs(date).endOf(filter);
|
||||
for (const booking of ourBookings) {
|
||||
const bookingEventTypeId = booking.source?.split("-")[1];
|
||||
if (
|
||||
// Only check OUR booking that matches the current eventTypeId
|
||||
// we don't care about another event type in this case as we dont need to know their booking limits
|
||||
!(bookingEventTypeId == eventType?.id && dayjs(booking.start).isBetween(startDate, endDate))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// increment total and check against the limit, adding a busy time if condition is met.
|
||||
total++;
|
||||
if (total >= limit) {
|
||||
bufferedBusyTimes.push({
|
||||
start: startDate.toISOString(),
|
||||
end: endDate.toISOString(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ export async function checkLimit({
|
|||
{
|
||||
id: eventId,
|
||||
bookings: {
|
||||
some: {
|
||||
every: {
|
||||
startTime: {
|
||||
gte: startDate,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user