Scheduling infrastructure for absolutely everyone.
fix: eventtype null cant be booked error (#18975)
Syed Ali Shahbaz92678dc042ca
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex 83190cb49c0..1fcdde96b1c 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -83,6 +83,7 @@"payment_not_created_error": "Payment could not be created","couldnt_charge_card_error": "Could not charge card for Payment","no_available_users_found_error": "No available users found. Could you try another time slot?",+ "booking_time_out_of_bounds_error": "The event type cannot be booked at this time. Could you try another time slot?","request_body_end_time_internal_error": "Internal Error. Request body does not contain end time","create_calendar_event_error": "Unable to create Calendar event in Organizer's calendar","update_calendar_event_error": "Unable to update Calendar event.",diff --git a/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts b/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.tsindex 81044e461fc..37342f057cf 100644--- a/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts+++ b/packages/features/bookings/lib/handleNewBooking/test/booking-limits.test.ts@@ -772,7 +772,9 @@ describe("handleNewBooking", () => {mockCalendarToHaveNoBusySlots("googlecalendar", {});await createBookingScenario(scenarioData);- await expect(() => handleNewBooking(req)).rejects.toThrowError("book a meeting in the past");+ await expect(() => handleNewBooking(req)).rejects.toThrowError(+ "Attempting to book a meeting in the past."+ );},timeout);@@ -865,7 +867,7 @@ describe("handleNewBooking", () => {},});- expect(() => handleNewBooking(req)).rejects.toThrowError("cannot be booked at this time");+ expect(() => handleNewBooking(req)).rejects.toThrowError("booking_time_out_of_bounds_error");},timeout);diff --git a/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts b/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.tsindex d17f39dd94b..10b1777dd8d 100644--- a/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts+++ b/packages/features/bookings/lib/handleNewBooking/validateBookingTimeIsNotOutOfBounds.ts@@ -1,6 +1,7 @@import type { Logger } from "tslog";import { getUTCOffsetByTimezone } from "@calcom/lib/date-fns";+import { ErrorCode } from "@calcom/lib/errorCodes";import { HttpError } from "@calcom/lib/http-error";import isOutOfBounds, { BookingDateInPastError } from "@calcom/lib/isOutOfBounds";import type { EventType } from "@calcom/prisma/client";@@ -15,6 +16,7 @@ type ValidateBookingTimeEventType = Pick<| "minimumBookingNotice"| "eventName"| "id"+ | "title">;export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBookingTimeEventType>(@@ -41,22 +43,14 @@ export const validateBookingTimeIsNotOutOfBounds = async <T extends ValidateBook);} catch (error) {logger.warn({- message: "NewBooking: Unable set timeOutOfBounds. Using false. ",+ message: "NewBooking: Unable to determine timeOutOfBounds status. Defaulting to false.",});+if (error instanceof BookingDateInPastError) {logger.info(`Booking eventType ${eventType.id} failed`, JSON.stringify({ error }));throw new HttpError({ statusCode: 400, message: error.message });}}- if (timeOutOfBounds) {- const error = {- errorCode: "BookingTimeOutOfBounds",- message: `EventType '${eventType.eventName}' cannot be booked at this time.`,- };- logger.warn({- message: `NewBooking: EventType '${eventType.eventName}' cannot be booked at this time.`,- });- throw new HttpError({ statusCode: 400, message: error.message });- }+ if (timeOutOfBounds) throw new Error(ErrorCode.BookingTimeOutOfBounds);};diff --git a/packages/lib/errorCodes.ts b/packages/lib/errorCodes.tsindex 8a36c61e5b9..1dcf6baef77 100644--- a/packages/lib/errorCodes.ts+++ b/packages/lib/errorCodes.ts@@ -16,4 +16,5 @@ export enum ErrorCode {UnableToSubscribeToThePlatform = "unable_to_subscribe_to_the_platform",UpdatingOauthClientError = "updating_oauth_client_error",CreatingOauthClientError = "creating_oauth_client_error",+ BookingTimeOutOfBounds = "booking_time_out_of_bounds_error",}diff --git a/packages/lib/isOutOfBounds.tsx b/packages/lib/isOutOfBounds.tsxindex 6f465988090..a9cd6f75f99 100644--- a/packages/lib/isOutOfBounds.tsx+++ b/packages/lib/isOutOfBounds.tsx@@ -250,6 +250,15 @@ export function isTimeViolatingFutureLimit({isAfterRollingEndDay,endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),});+ if (isAfterRollingEndDay)+ log.warn(+ "Booking is out of bounds due to rolling period end day.",+ safeStringify({+ formattedDate: dateInSystemTz.format(),+ isAfterRollingEndDay,+ endOfRollingPeriodEndDayInBookerTz: periodLimits.endOfRollingPeriodEndDayInBookerTz.format(),+ })+ );return isAfterRollingEndDay;}@@ -263,6 +272,17 @@ export function isTimeViolatingFutureLimit({startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),});+ if (isBeforeRangeStart || isAfterRangeEnd)+ log.warn(+ "Booking is out of bounds due to range start and end.",+ safeStringify({+ formattedDate: dateInSystemTz.format(),+ isBeforeRangeStart,+ isAfterRangeEnd,+ startOfRangeStartDayInEventTz: periodLimits.startOfRangeStartDayInEventTz.format(),+ endOfRangeEndDayInEventTz: periodLimits.endOfRangeEndDayInEventTz.format(),+ })+ );return isBeforeRangeStart || isAfterRangeEnd;}return false;@@ -287,22 +307,37 @@ export default function isOutOfBounds(},minimumBookingNotice?: number) {- return (- isTimeOutOfBounds({ time, minimumBookingNotice }) ||- isTimeViolatingFutureLimit({- time,- periodLimits: calculatePeriodLimits({- periodType,- periodDays,- periodCountCalendarDays,- periodStartDate,- periodEndDate,- // Temporary till we find a way to provide allDatesWithBookabilityStatus in handleNewBooking without re-computing availability for the booked timeslot- allDatesWithBookabilityStatusInBookerTz: null,- _skipRollingWindowCheck: true,- eventUtcOffset,- bookerUtcOffset,- }),- })- );+ const log = logger.getSubLogger({ prefix: ["isOutOfBounds"] });+ const isOutOfBoundsByTime = isTimeOutOfBounds({ time, minimumBookingNotice });+ const periodLimits = calculatePeriodLimits({+ periodType,+ periodDays,+ periodCountCalendarDays,+ periodStartDate,+ periodEndDate,+ allDatesWithBookabilityStatusInBookerTz: null, // Temporary workaround+ _skipRollingWindowCheck: true,+ eventUtcOffset,+ bookerUtcOffset,+ });++ const isOutOfBoundsByPeriod = isTimeViolatingFutureLimit({+ time,+ periodLimits,+ });++ if (isOutOfBoundsByTime) {+ log.warn(+ "Booking is out of bounds due to minimum booking notice.",+ safeStringify({ minimumBookingNotice })+ );+ return true;+ }++ if (isOutOfBoundsByPeriod) {+ log.warn("Booking is out of bounds due to period restrictions", safeStringify({ periodLimits }));+ return true;+ }++ return false;}