Skip to content

Commit

Permalink
fix: API booking issues (#15247)
Browse files Browse the repository at this point in the history
* fix: API booking issues

* Put back the optional zod for user

* fixed the imports

* Using nullish

* typing errors

* missed one
  • Loading branch information
keithwillcode authored May 29, 2024
1 parent 5fb5081 commit 5f082e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/api/v1/lib/validations/booking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const schemaBookingReadPublic = Booking.extend({
timeZone: true,
locale: true,
})
.optional(),
.nullish(),
payment: z
.array(
_PaymentModel.pick({
Expand Down
13 changes: 12 additions & 1 deletion apps/api/v1/pages/api/bookings/_post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { NextApiRequest } from "next";

import getBookingDataSchemaForApi from "@calcom/features/bookings/lib/getBookingDataSchemaForApi";
import handleNewBooking from "@calcom/features/bookings/lib/handleNewBooking";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { HttpError } from "@calcom/lib/http-error";
import { defaultResponder } from "@calcom/lib/server";

import { getAccessibleUsers } from "~/lib/utils/retrieveScopedAccessibleUsers";
Expand Down Expand Up @@ -218,7 +220,16 @@ async function handler(req: NextApiRequest) {
req.userId = requestedUserId || userId;
}

return await handleNewBooking(req, getBookingDataSchemaForApi);
try {
return await handleNewBooking(req, getBookingDataSchemaForApi);
} catch (error: unknown) {
const knownError = error as Error;
if (knownError?.message === ErrorCode.NoAvailableUsersFound) {
throw new HttpError({ statusCode: 400, message: knownError.message });
}

throw error;
}
}

export default defaultResponder(handler);

0 comments on commit 5f082e1

Please sign in to comment.