2022-03-26 21:29:30 +00:00
|
|
|
import { withValidation } from "next-validations";
|
2022-04-01 15:53:52 +00:00
|
|
|
import { z } from "zod";
|
2022-03-26 21:29:30 +00:00
|
|
|
|
2022-03-30 15:37:51 +00:00
|
|
|
import { _BookingModel as Booking } from "@calcom/prisma/zod";
|
|
|
|
|
2022-04-01 15:53:52 +00:00
|
|
|
// Here we remove any parameters that are not needed for the API with omit.
|
|
|
|
const schemaBookingBaseBodyParams = Booking.omit({ id: true }).partial();
|
|
|
|
// Here we redeclare the required ones after removing the ones we don't need.
|
|
|
|
// and making the rest optional with .partial()
|
|
|
|
const schemaBookingRequiredParams = z.object({
|
|
|
|
uid: z.string(),
|
|
|
|
title: z.string(),
|
|
|
|
startTime: z.date(),
|
|
|
|
endTime: z.date(),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const schemaBookingBodyParams = schemaBookingBaseBodyParams.merge(schemaBookingRequiredParams);
|
2022-03-30 15:37:51 +00:00
|
|
|
|
|
|
|
export const schemaBookingPublic = Booking.omit({});
|
|
|
|
|
|
|
|
export const withValidBooking = withValidation({
|
|
|
|
schema: schemaBookingBodyParams,
|
2022-03-26 21:29:30 +00:00
|
|
|
type: "Zod",
|
|
|
|
mode: "body",
|
|
|
|
});
|