Skip to content

Scheduling infrastructure for absolutely everyone.

fix: add eventTypeId and eventTypeSlug guard (#25773)

Udit Takkar2c7cb530a111
diff --git a/apps/api/v1/test/lib/bookings/_post.test.ts b/apps/api/v1/test/lib/bookings/_post.test.ts
index 3e397eefc28..de13aeb627b 100644
--- a/apps/api/v1/test/lib/bookings/_post.test.ts
+++ b/apps/api/v1/test/lib/bookings/_post.test.ts
@@ -245,7 +245,9 @@ describe("POST /api/bookings", () => {
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
method: "POST",
- body: {},
+ body: {
+ eventTypeId: 2,
+ },
});
await handler(req, res);
diff --git a/packages/features/bookings/lib/handleNewBooking/getEventType.ts b/packages/features/bookings/lib/handleNewBooking/getEventType.ts
index bb5313375b3..ba0fa32b8c9 100644
--- a/packages/features/bookings/lib/handleNewBooking/getEventType.ts
+++ b/packages/features/bookings/lib/handleNewBooking/getEventType.ts
@@ -1,4 +1,5 @@
import { getDefaultEvent } from "@calcom/features/eventtypes/lib/defaultEvents";
+import { HttpError } from "@calcom/lib/http-error";
import { withReporting } from "@calcom/lib/sentryWrapper";
import { getBookingFieldsWithSystemFields } from "../getBookingFields";
@@ -11,6 +12,10 @@ const _getEventType = async ({
eventTypeId: number;
eventTypeSlug?: string;
}) => {
+ if (!eventTypeId && !eventTypeSlug) {
+ throw new HttpError({ statusCode: 400, message: "Either eventTypeId or eventTypeSlug must be provided" });
+ }
+
// handle dynamic user
const eventType =
!eventTypeId && !!eventTypeSlug ? getDefaultEvent(eventTypeSlug) : await getEventTypesFromDB(eventTypeId);