diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index ec33f5bbfc..7971b4ebab 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -26,7 +26,7 @@ "dependencies": { "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.31", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.33", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/apps/api/v2/src/ee/bookings/controllers/bookings.controller.e2e-spec.ts b/apps/api/v2/src/ee/bookings/controllers/bookings.controller.e2e-spec.ts index cec587562a..698c869e9f 100644 --- a/apps/api/v2/src/ee/bookings/controllers/bookings.controller.e2e-spec.ts +++ b/apps/api/v2/src/ee/bookings/controllers/bookings.controller.e2e-spec.ts @@ -22,7 +22,7 @@ import { withApiAuth } from "test/utils/withApiAuth"; import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants"; import { handleNewBooking } from "@calcom/platform-libraries"; -import { ApiSuccessResponse, ApiResponse } from "@calcom/platform-types"; +import { ApiSuccessResponse, ApiResponse, ApiErrorResponse } from "@calcom/platform-types"; describe("Bookings Endpoints", () => { describe("User Authenticated", () => { @@ -144,6 +144,49 @@ describe("Bookings Endpoints", () => { }); }); + it("should fail to create a booking with no_available_users_found_error", async () => { + const bookingStart = "2040-05-21T09:30:00.000Z"; + const bookingEnd = "2040-05-21T10:30:00.000Z"; + const bookingEventTypeId = eventTypeId; + const bookingTimeZone = "Europe/London"; + const bookingLanguage = "en"; + const bookingHashedLink = ""; + const bookingMetadata = { + timeFormat: "12", + meetingType: "organizer-phone", + }; + const bookingResponses = { + name: "tester", + email: "tester@example.com", + location: { + value: "link", + optionValue: "", + }, + notes: "test", + guests: [], + }; + + const body: CreateBookingInput = { + start: bookingStart, + end: bookingEnd, + eventTypeId: bookingEventTypeId, + timeZone: bookingTimeZone, + language: bookingLanguage, + metadata: bookingMetadata, + hashedLink: bookingHashedLink, + responses: bookingResponses, + }; + + return request(app.getHttpServer()) + .post("/v2/bookings") + .send(body) + .expect(400) + .then(async (response) => { + const responseBody: ApiErrorResponse = response.body; + expect(responseBody.error.message).toEqual("no_available_users_found_error"); + }); + }); + it("should create a booking with api key to get owner id", async () => { const bookingStart = "2040-05-22T09:30:00.000Z"; const bookingEnd = "2040-05-22T10:30:00.000Z"; diff --git a/apps/api/v2/src/ee/bookings/controllers/bookings.controller.ts b/apps/api/v2/src/ee/bookings/controllers/bookings.controller.ts index 0ce1889610..0f5a1f2344 100644 --- a/apps/api/v2/src/ee/bookings/controllers/bookings.controller.ts +++ b/apps/api/v2/src/ee/bookings/controllers/bookings.controller.ts @@ -49,6 +49,7 @@ import { getBookingInfo, handleCancelBooking, getBookingForReschedule, + ErrorCode, } from "@calcom/platform-libraries"; import { GetBookingsInput, CancelBookingInput, Status } from "@calcom/platform-types"; import { ApiResponse } from "@calcom/platform-types"; @@ -366,6 +367,9 @@ export class BookingsController { if (err instanceof Error) { const error = err as Error; + if (Object.values(ErrorCode).includes(error.message as unknown as ErrorCode)) { + throw new HttpException(error.message, 400); + } throw new InternalServerErrorException(error?.message ?? errMsg); } diff --git a/packages/platform/libraries/index.ts b/packages/platform/libraries/index.ts index e8e5083f13..77f74c1001 100644 --- a/packages/platform/libraries/index.ts +++ b/packages/platform/libraries/index.ts @@ -8,7 +8,7 @@ import { getPublicEvent } from "@calcom/features/eventtypes/lib/getPublicEvent"; import handleMarkNoShow from "@calcom/features/handleMarkNoShow"; import * as instantMeetingMethods from "@calcom/features/instant-meeting/handleInstantMeeting"; import getAllUserBookings from "@calcom/lib/bookings/getAllUserBookings"; -import { symmetricEncrypt } from "@calcom/lib/crypto"; +import { symmetricEncrypt, symmetricDecrypt } from "@calcom/lib/crypto"; import { getTranslation } from "@calcom/lib/server/i18n"; import { updateHandler as updateScheduleHandler } from "@calcom/trpc/server/routers/viewer/availability/schedule/update.handler"; import { getAvailableSlots } from "@calcom/trpc/server/routers/viewer/slots/util"; @@ -112,7 +112,7 @@ export type { SystemField, UserField } from "@calcom/lib/event-types/transformer export { parseRecurringEvent } from "@calcom/lib/isRecurringEvent"; export { dynamicEvent } from "@calcom/lib/defaultEvents"; -export { symmetricEncrypt }; +export { symmetricEncrypt, symmetricDecrypt }; export { CalendarService }; export { getCalendar }; @@ -120,3 +120,5 @@ export { getCalendar }; export { getTranslation }; export { updateNewTeamMemberEventTypes } from "@calcom/lib/server/queries"; + +export { ErrorCode } from "@calcom/lib/errorCodes";