Booking Limits checking ALL events not the event the limit is applied too (#5601)
* Fix error message * Only apply buffer limits to That event type * Correctly get eventtypeId in source * Add comment * Move to i188n strings * Wrap string to be translated Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
co-authored by
Alex van Andel
parent
994df45a19
commit
9441a79def
@@ -911,7 +911,7 @@ function ErrorMessage({ error }: { error: unknown }) {
|
||||
<div className="ltr:ml-3 rtl:mr-3">
|
||||
<p className="text-sm text-yellow-700">
|
||||
{rescheduleUid ? t("reschedule_fail") : t("booking_fail")}{" "}
|
||||
{error instanceof HttpError || error instanceof Error ? error.message : "Unknown error"}
|
||||
{error instanceof HttpError || error instanceof Error ? t(error.message) : "Unknown error"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1372,5 +1372,6 @@
|
||||
"test_preview": "Test Preview",
|
||||
"route_to": "Route to",
|
||||
"test_preview_description": "Test your routing form without submitting any data",
|
||||
"test_routing": "Test Routing"
|
||||
"test_routing": "Test Routing",
|
||||
"booking_limit_reached":"Booking Limit for this event type has been reached"
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ export async function getBusyTimes(params: {
|
||||
title: true,
|
||||
eventType: {
|
||||
select: {
|
||||
id: true,
|
||||
afterEventBuffer: true,
|
||||
beforeEventBuffer: true,
|
||||
},
|
||||
@@ -67,7 +68,7 @@ export async function getBusyTimes(params: {
|
||||
.add((eventType?.afterEventBuffer || 0) + (beforeEventBuffer || 0), "minute")
|
||||
.toDate(),
|
||||
title,
|
||||
source: `eventType-${eventTypeId}-booking-${id}`,
|
||||
source: `eventType-${eventType?.id}-booking-${id}`,
|
||||
}))
|
||||
);
|
||||
logger.silly(`Busy Time from Cal Bookings ${JSON.stringify(busyTimes)}`);
|
||||
|
||||
@@ -202,10 +202,13 @@ export async function getUserAvailability(
|
||||
const startDate = dayjs(booking.start).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++;
|
||||
if (total >= limit)
|
||||
// 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() });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function checkLimit({
|
||||
}
|
||||
|
||||
throw new HttpError({
|
||||
message: `Booking limit of ${limitingNumber}/${filter} reached for this eventType`,
|
||||
message: `booking_limit_reached`,
|
||||
statusCode: 403,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user