Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Slots are available even after exceeding the booking limits for the team event (#21801)

Anik Dhabal Babu601df7f80870
diff --git a/packages/lib/intervalLimits/limitManager.ts b/packages/lib/intervalLimits/limitManager.ts
index e659b3c404c..79401843954 100644
--- a/packages/lib/intervalLimits/limitManager.ts
+++ b/packages/lib/intervalLimits/limitManager.ts
@@ -58,6 +58,17 @@ export default class LimitManager {
});
}
+ /**
+ * Merges busy times from another LimitManager
+ */
+ mergeBusyTimes(otherManager: LimitManager) {
+ otherManager.busyMap.forEach((busyTime, key) => {
+ if (!this.busyMap.has(key)) {
+ this.busyMap.set(key, busyTime);
+ }
+ });
+ }
+
/**
* Returns all busy times
*/
diff --git a/packages/trpc/server/routers/viewer/slots/util.ts b/packages/trpc/server/routers/viewer/slots/util.ts
index 202701f2b9b..53de7a09491 100644
--- a/packages/trpc/server/routers/viewer/slots/util.ts
+++ b/packages/trpc/server/routers/viewer/slots/util.ts
@@ -30,7 +30,7 @@ import { parseBookingLimit } from "@calcom/lib/intervalLimits/isBookingLimits";
import { parseDurationLimit } from "@calcom/lib/intervalLimits/isDurationLimits";
import LimitManager from "@calcom/lib/intervalLimits/limitManager";
import { checkBookingLimit } from "@calcom/lib/intervalLimits/server/checkBookingLimits";
-import { getUnitFromBusyTime, isBookingWithinPeriod } from "@calcom/lib/intervalLimits/utils";
+import { isBookingWithinPeriod } from "@calcom/lib/intervalLimits/utils";
import {
calculatePeriodLimits,
isTimeOutOfBounds,
@@ -1031,13 +1031,7 @@ const _getBusyTimesFromLimitsForUsers = async (
const userBookings = busyTimesFromLimitsBookings.filter((booking) => booking.userId === user.id);
const limitManager = new LimitManager();
- for (const busyTime of globalLimitManager.getBusyTimes()) {
- const start = dayjs(busyTime.start);
- const end = dayjs(busyTime.end);
- const unit = getUnitFromBusyTime(start, end);
-
- limitManager.addBusyTime(start, unit, timeZone);
- }
+ limitManager.mergeBusyTimes(globalLimitManager);
if (bookingLimits) {
for (const key of descendingLimitKeys) {
@@ -1222,13 +1216,8 @@ const _getBusyTimesFromTeamLimitsForUsers = async (
const userBusyTimes = busyTimes.filter((busyTime) => busyTime.userId === user.id);
const limitManager = new LimitManager();
- for (const busyTime of globalLimitManager.getBusyTimes()) {
- const start = dayjs(busyTime.start);
- const end = dayjs(busyTime.end);
- const unit = getUnitFromBusyTime(start, end);
+ limitManager.mergeBusyTimes(globalLimitManager);
- limitManager.addBusyTime(start, unit, timeZone);
- }
const bookingLimitsParams = {
bookings: userBusyTimes,
bookingLimits,