fix: API booking issues (#15247)

* fix: API booking issues

* Put back the optional zod for user

* fixed the imports

* Using nullish

* typing errors

* missed one
This commit is contained in:
Keith Williams
2024-05-29 16:16:49 +00:00
committed by GitHub
parent 5fb5081faa
commit 5f082e11f8
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ export const schemaBookingReadPublic = Booking.extend({
timeZone: true,
locale: true,
})
.optional(),
.nullish(),
payment: z
.array(
_PaymentModel.pick({
+12 -1
View File
@@ -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";
@@ -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);