Scheduling infrastructure for absolutely everyone.
Booking Limits checking ALL events not the event the limit is applied too (#5601)
sean-brydon9441a79def5c
diff --git a/apps/web/components/booking/pages/BookingPage.tsx b/apps/web/components/booking/pages/BookingPage.tsxindex b1cca05ff52..bb27d4b03c5 100644--- a/apps/web/components/booking/pages/BookingPage.tsx+++ b/apps/web/components/booking/pages/BookingPage.tsx@@ -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>diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex d64fb23169d..99a8061ad3d 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -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"}diff --git a/packages/core/getBusyTimes.ts b/packages/core/getBusyTimes.tsindex 8baa2d6a642..e000a983b6b 100644--- a/packages/core/getBusyTimes.ts+++ b/packages/core/getBusyTimes.ts@@ -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)}`);diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.tsindex bfeeb0171f9..0ddddeb227f 100644--- a/packages/core/getUserAvailability.ts+++ b/packages/core/getUserAvailability.ts@@ -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() });+ }});}}diff --git a/packages/lib/server/checkBookingLimits.ts b/packages/lib/server/checkBookingLimits.tsindex c18b431ae7b..7d81c1dd105 100644--- a/packages/lib/server/checkBookingLimits.ts+++ b/packages/lib/server/checkBookingLimits.ts@@ -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,});}