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:
@@ -55,7 +55,7 @@ export const schemaBookingReadPublic = Booking.extend({
|
||||
timeZone: true,
|
||||
locale: true,
|
||||
})
|
||||
.optional(),
|
||||
.nullish(),
|
||||
payment: z
|
||||
.array(
|
||||
_PaymentModel.pick({
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user