Skip to content

Scheduling infrastructure for absolutely everyone.

fix: bookings ilmits errror (#16739)

Carina Wollendorferb84cdc0d453d
diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts
index d8f87e846cf..41f2f8062d0 100644
--- a/apps/web/test/lib/getSchedule.test.ts
+++ b/apps/web/test/lib/getSchedule.test.ts
@@ -1151,6 +1151,87 @@ describe("getSchedule", () => {
expect(availableSlotsInTz.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(23); // 2 booking per day as limit, only one booking on that
});
+ test("test that booking limit is working correctly if user is all day available and attendee is in different timezone than host", async () => {
+ const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
+ const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
+ const { dateString: plus3DateString } = getDate({ dateIncrement: 3 });
+
+ const scenarioData = {
+ eventTypes: [
+ {
+ id: 1,
+ length: 60,
+ beforeEventBuffer: 0,
+ afterEventBuffer: 0,
+ bookingLimits: {
+ PER_DAY: 1,
+ },
+ users: [
+ {
+ id: 101,
+ },
+ ],
+ },
+ ],
+ users: [
+ {
+ ...TestData.users.example,
+ id: 101,
+ schedules: [
+ {
+ id: 1,
+ name: "All Day available",
+ availability: [
+ {
+ userId: null,
+ eventTypeId: null,
+ days: [0, 1, 2, 3, 4, 5, 6],
+ startTime: new Date("1970-01-01T00:00:00.000Z"),
+ endTime: new Date("1970-01-01T23:59:59.999Z"),
+ date: null,
+ },
+ ],
+ timeZone: Timezones["+6:00"],
+ },
+ ],
+ },
+ ],
+ // One bookings for each(E1 and E2) on plus2Date
+ bookings: [
+ {
+ userId: 101,
+ eventTypeId: 1,
+ startTime: `${plus2DateString}T08:00:00.000Z`,
+ endTime: `${plus2DateString}T09:00:00.000Z`,
+ status: "ACCEPTED" as BookingStatus,
+ },
+ ],
+ };
+
+ await createBookingScenario(scenarioData);
+
+ const thisUserAvailabilityBookingLimit = await getSchedule({
+ input: {
+ eventTypeId: 1,
+ eventTypeSlug: "",
+ startTime: `${plus1DateString}T00:00:00.000Z`,
+ endTime: `${plus3DateString}T23:59:59.999Z`,
+ timeZone: Timezones["-11:00"], //attendee timezone
+ isTeamEvent: false,
+ orgSlug: null,
+ },
+ });
+
+ const availableSlotsInTz: dayjs.Dayjs[] = [];
+ for (const date in thisUserAvailabilityBookingLimit.slots) {
+ thisUserAvailabilityBookingLimit.slots[date].forEach((timeObj) => {
+ availableSlotsInTz.push(dayjs(timeObj.time).tz(Timezones["+6:00"]));
+ });
+ }
+
+ expect(availableSlotsInTz.filter((slot) => slot.format().startsWith(plus2DateString)).length).toBe(0); // 1 booking per day as limit
+ });
+
test("a slot counts as being busy when the eventType is requiresConfirmation and requiresConfirmationWillBlockSlot", async () => {
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts
index e79a1d4c2d1..5c26f139b49 100644
--- a/packages/core/getUserAvailability.ts
+++ b/packages/core/getUserAvailability.ts
@@ -266,6 +266,14 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
currentSeats = await getCurrentSeats(eventType, dateFrom, dateTo);
}
+ const userSchedule = user.schedules.filter(
+ (schedule) => !user?.defaultScheduleId || schedule.id === user?.defaultScheduleId
+ )[0];
+
+ const schedule = eventType?.schedule ? eventType.schedule : userSchedule;
+
+ const timeZone = schedule?.timeZone || eventType?.timeZone || user.timeZone;
+
const bookingLimits = parseBookingLimit(eventType?.bookingLimits);
const durationLimits = parseDurationLimit(eventType?.durationLimits);
@@ -274,8 +282,8 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
? await getBusyTimesFromLimits(
bookingLimits,
durationLimits,
- dateFrom,
- dateTo,
+ dateFrom.tz(timeZone),
+ dateTo.tz(timeZone),
duration,
eventType,
initialData?.busyTimesFromLimitsBookings ?? []
@@ -314,12 +322,6 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
...busyTimesFromLimits,
];
- const userSchedule = user.schedules.filter(
- (schedule) => !user?.defaultScheduleId || schedule.id === user?.defaultScheduleId
- )[0];
-
- const schedule = eventType?.schedule ? eventType.schedule : userSchedule;
-
const isDefaultSchedule = userSchedule && userSchedule.id === schedule.id;
log.debug(
@@ -333,8 +335,6 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA
const startGetWorkingHours = performance.now();
- const timeZone = schedule?.timeZone || eventType?.timeZone || user.timeZone;
-
if (
!(schedule?.availability || (eventType?.availability.length ? eventType.availability : user.availability))
) {