From a88eb0fdc5e93d68bd1a3b798ddecd08d62bc71a Mon Sep 17 00:00:00 2001 From: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Date: Tue, 2 May 2023 16:38:56 +0200 Subject: [PATCH] Allow booking date overrides outside of working hours (#8538) * allow booking on date overrides outside of working hours * remove comment --------- Co-authored-by: CarinaWolli --- .../features/bookings/lib/handleNewBooking.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 32d93194b2..338ecda022 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -65,7 +65,7 @@ import { import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime"; import type { AdditionalInformation, AppsStatus, CalendarEvent, Person } from "@calcom/types/Calendar"; import type { EventResult, PartialReference } from "@calcom/types/EventManager"; -import type { WorkingHours } from "@calcom/types/schedule"; +import type { WorkingHours, TimeRange as DateOverride } from "@calcom/types/schedule"; import type { EventTypeInfo } from "../../webhooks/lib/sendPayload"; import sendPayload from "../../webhooks/lib/sendPayload"; @@ -118,10 +118,14 @@ const isWithinAvailableHours = ( timeSlot: { start: ConfigType; end: ConfigType }, { workingHours, + dateOverrides, organizerTimeZone, + inviteeTimeZone, }: { workingHours: WorkingHours[]; + dateOverrides: DateOverride[]; organizerTimeZone: string; + inviteeTimeZone: string; } ) => { const timeSlotStart = dayjs(timeSlot.start).utc(); @@ -145,6 +149,22 @@ const isWithinAvailableHours = ( return true; } } + + // check if it is a date override + for (const dateOverride of dateOverrides) { + const utcOffSet = dayjs(dateOverride.start).tz(inviteeTimeZone).utcOffset(); + + const slotStart = dayjs(timeSlotStart).add(utcOffSet, "minute"); + const slotEnd = dayjs(timeSlotEnd).add(utcOffSet, "minute"); + + if ( + slotStart.isBetween(dateOverride.start, dateOverride.end) && + slotEnd.isBetween(dateOverride.start, dateOverride.end) + ) { + return true; + } + } + log.error( `NAUF: isWithinAvailableHours ${JSON.stringify({ ...timeSlot, organizerTimeZone, workingHours })}` ); @@ -303,7 +323,11 @@ async function ensureAvailableUsers( const availableUsers: IsFixedAwareUser[] = []; /** Let's start checking for availability */ for (const user of eventType.users) { - const { busy: bufferedBusyTimes, workingHours } = await getUserAvailability( + const { + busy: bufferedBusyTimes, + workingHours, + dateOverrides, + } = await getUserAvailability( { userId: user.id, eventTypeId: eventType.id, @@ -318,7 +342,9 @@ async function ensureAvailableUsers( { start: input.dateFrom, end: input.dateTo }, { workingHours, + dateOverrides, organizerTimeZone: eventType.timeZone || eventType?.schedule?.timeZone || user.timeZone, + inviteeTimeZone: input.timeZone, } ) ) {