Scheduling infrastructure for absolutely everyone.
fix: confirm booking doesn't respect minimum booking notice (#14577)
Abhiuday Guptafc16ec59d367
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.tsindex 8f5090ed8bb..03246cbd9b3 100644--- a/packages/features/bookings/lib/handleNewBooking.ts+++ b/packages/features/bookings/lib/handleNewBooking.ts@@ -15,9 +15,9 @@ import processExternalId from "@calcom/app-store/_utils/calendars/processExternaimport { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_metadata";import type { LocationObject } from "@calcom/app-store/locations";import {- getLocationValueForDB,MeetLocationType,OrganizerDefaultConferencingAppType,+ getLocationValueForDB,} from "@calcom/app-store/locations";import type { EventTypeAppsList } from "@calcom/app-store/utils";import { getAppFromSlug } from "@calcom/app-store/utils";@@ -54,8 +54,12 @@ import { getFullName } from "@calcom/features/form-builder/utils";import type { GetSubscriberOptions } from "@calcom/features/webhooks/lib/getWebhooks";import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";import { cancelScheduledJobs, scheduleTrigger } from "@calcom/features/webhooks/lib/scheduleTrigger";-import { parseBookingLimit, parseDurationLimit } from "@calcom/lib";-import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";+import {+ isPrismaObjOrUndefined,+ parseBookingLimit,+ parseDurationLimit,+ parseRecurringEvent,+} from "@calcom/lib";import { getVideoCallUrlFromCalEvent } from "@calcom/lib/CalEventParser";import { getDefaultEvent, getUsernameList } from "@calcom/lib/defaultEvents";import { ErrorCode } from "@calcom/lib/errorCodes";@@ -80,9 +84,9 @@ import type { BookingReference } from "@calcom/prisma/client";import { BookingStatus, SchedulingType, WebhookTriggerEvents } from "@calcom/prisma/enums";import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";import {+ EventTypeMetaDataSchema,bookingCreateSchemaLegacyPropsForApi,customInputSchema,- EventTypeMetaDataSchema,userMetadata as userMetadataSchema,} from "@calcom/prisma/zod-utils";import type {@@ -193,6 +197,7 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {lockTimeZoneToggleOnBookingPage: true,requiresConfirmation: true,requiresBookerEmailVerification: true,+ minimumBookingNotice: true,userId: true,price: true,currency: true,@@ -701,6 +706,7 @@ async function createBooking({newBookingData.recurringEventId = originalRescheduledBooking.recurringEventId;}}+const createBookingObj = {include: {user: {@@ -1008,13 +1014,17 @@ async function handler(let timeOutOfBounds = false;try {- timeOutOfBounds = isOutOfBounds(reqBody.start, {- periodType: eventType.periodType,- periodDays: eventType.periodDays,- periodEndDate: eventType.periodEndDate,- periodStartDate: eventType.periodStartDate,- periodCountCalendarDays: eventType.periodCountCalendarDays,- });+ timeOutOfBounds = isOutOfBounds(+ reqBody.start,+ {+ periodType: eventType.periodType,+ periodDays: eventType.periodDays,+ periodEndDate: eventType.periodEndDate,+ periodStartDate: eventType.periodStartDate,+ periodCountCalendarDays: eventType.periodCountCalendarDays,+ },+ eventType.minimumBookingNotice+ );} catch (error) {loggerWithEventDetails.warn({message: "NewBooking: Unable set timeOutOfBounds. Using false. ",diff --git a/packages/lib/isOutOfBounds.tsx b/packages/lib/isOutOfBounds.tsxindex d66a73e0811..7779dbb2784 100644--- a/packages/lib/isOutOfBounds.tsx+++ b/packages/lib/isOutOfBounds.tsx@@ -28,13 +28,21 @@ function isOutOfBounds(}: Pick<EventType,"periodType" | "periodDays" | "periodCountCalendarDays" | "periodStartDate" | "periodEndDate"- >+ >,+ minimumBookingNotice?: number) {const date = dayjs(time);guardAgainstBookingInThePast(date.toDate());periodDays = periodDays || 0;+ if (minimumBookingNotice) {+ const minimumBookingStartDate = dayjs().add(minimumBookingNotice, "minutes");+ if (date.isBefore(minimumBookingStartDate)) {+ return true;+ }+ }+switch (periodType) {case PeriodType.ROLLING: {const periodRollingEndDay = periodCountCalendarDays