diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 5b99871105..8ab5a9857b 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -1287,6 +1287,7 @@ "default_calendar_selected": "Default calendar", "hide_from_profile": "Hide from profile", "event_setup_tab_title": "Event Setup", + "availability_not_found_in_schedule_error":"No availability found in schedule", "event_limit_tab_title": "Limits", "event_limit_tab_description": "How often you can be booked", "event_advanced_tab_description": "Calendar settings & more...", diff --git a/packages/core/getUserAvailability.ts b/packages/core/getUserAvailability.ts index 4f33347792..e955531ae5 100644 --- a/packages/core/getUserAvailability.ts +++ b/packages/core/getUserAvailability.ts @@ -6,6 +6,7 @@ import dayjs from "@calcom/dayjs"; import { parseBookingLimit, parseDurationLimit } from "@calcom/lib"; import { getWorkingHours } from "@calcom/lib/availability"; import { buildDateRanges, subtract } from "@calcom/lib/date-ranges"; +import { ErrorCode } from "@calcom/lib/errorCodes"; import { HttpError } from "@calcom/lib/http-error"; import { descendingLimitKeys, intervalLimitKeyToUnit } from "@calcom/lib/intervalLimit"; import logger from "@calcom/lib/logger"; @@ -258,6 +259,7 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA const useHostSchedulesForTeamEvent = eventType?.metadata?.config?.useHostSchedulesForTeamEvent; const schedule = !useHostSchedulesForTeamEvent && eventType?.schedule ? eventType.schedule : userSchedule; + log.debug( "Using schedule:", safeStringify({ @@ -272,8 +274,14 @@ const _getUserAvailability = async function getUsersWorkingHoursLifeTheUniverseA const timeZone = schedule?.timeZone || eventType?.timeZone || user.timeZone; + if ( + !(schedule?.availability || (eventType?.availability.length ? eventType.availability : user.availability)) + ) { + throw new HttpError({ statusCode: 400, message: ErrorCode.AvailabilityNotFoundInSchedule }); + } + const availability = ( - schedule.availability || (eventType?.availability.length ? eventType.availability : user.availability) + schedule?.availability || (eventType?.availability.length ? eventType.availability : user.availability) ).map((a) => ({ ...a, userId: user.id, diff --git a/packages/lib/errorCodes.ts b/packages/lib/errorCodes.ts index e7320a5726..743820d471 100644 --- a/packages/lib/errorCodes.ts +++ b/packages/lib/errorCodes.ts @@ -6,5 +6,6 @@ export enum ErrorCode { AlreadySignedUpForBooking = "already_signed_up_for_this_booking_error", HostsUnavailableForBooking = "hosts_unavailable_for_booking", EventTypeNotFound = "event_type_not_found_error", + AvailabilityNotFoundInSchedule = "availability_not_found_in_schedule_error", CancelledBookingsCannotBeRescheduled = "cancelled_bookings_cannot_be_rescheduled", }