fixes:- https://secure.helpscout.net/conversation/2117165409/2395 How to test? Create an event type with custom inputs GET Request on /event-types end point After:- <img width="1440" alt="Screenshot 2023-01-07 at 4 57 39 PM" src="https://user-images.githubusercontent.com/53316345/211147930-1154f1ad-5309-4e9c-b2e0-164169717d47.png"> Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
129 lines
3.2 KiB
TypeScript
129 lines
3.2 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { _EventTypeModel as EventType } from "@calcom/prisma/zod";
|
|
import { customInputSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
import { Frequency } from "~/lib/types";
|
|
|
|
import { jsonSchema } from "./shared/jsonSchema";
|
|
import { schemaQueryUserId } from "./shared/queryUserId";
|
|
import { timeZone } from "./shared/timeZone";
|
|
|
|
const recurringEventInputSchema = z.object({
|
|
dtstart: z.string().optional(),
|
|
interval: z.number().int().optional(),
|
|
count: z.number().int().optional(),
|
|
freq: z.nativeEnum(Frequency).optional(),
|
|
until: z.string().optional(),
|
|
tzid: timeZone.optional(),
|
|
});
|
|
|
|
export const schemaEventTypeBaseBodyParams = EventType.pick({
|
|
title: true,
|
|
description: true,
|
|
slug: true,
|
|
length: true,
|
|
hidden: true,
|
|
position: true,
|
|
teamId: true,
|
|
eventName: true,
|
|
timeZone: true,
|
|
periodType: true,
|
|
periodStartDate: true,
|
|
periodEndDate: true,
|
|
periodDays: true,
|
|
periodCountCalendarDays: true,
|
|
requiresConfirmation: true,
|
|
disableGuests: true,
|
|
hideCalendarNotes: true,
|
|
minimumBookingNotice: true,
|
|
beforeEventBuffer: true,
|
|
afterEventBuffer: true,
|
|
schedulingType: true,
|
|
price: true,
|
|
currency: true,
|
|
slotInterval: true,
|
|
successRedirectUrl: true,
|
|
locations: true,
|
|
})
|
|
.partial()
|
|
.strict();
|
|
|
|
const schemaEventTypeCreateParams = z
|
|
.object({
|
|
title: z.string(),
|
|
slug: z.string(),
|
|
description: z.string().optional().nullable(),
|
|
length: z.number().int(),
|
|
metadata: z.any().optional(),
|
|
recurringEvent: recurringEventInputSchema.optional(),
|
|
seatsPerTimeSlot: z.number().optional(),
|
|
seatsShowAttendees: z.boolean().optional(),
|
|
})
|
|
.strict();
|
|
|
|
export const schemaEventTypeCreateBodyParams = schemaEventTypeBaseBodyParams
|
|
.merge(schemaEventTypeCreateParams)
|
|
.merge(schemaQueryUserId.partial());
|
|
|
|
const schemaEventTypeEditParams = z
|
|
.object({
|
|
title: z.string().optional(),
|
|
slug: z.string().optional(),
|
|
length: z.number().int().optional(),
|
|
seatsPerTimeSlot: z.number().optional(),
|
|
seatsShowAttendees: z.boolean().optional(),
|
|
})
|
|
.strict();
|
|
|
|
export const schemaEventTypeEditBodyParams = schemaEventTypeBaseBodyParams.merge(schemaEventTypeEditParams);
|
|
export const schemaEventTypeReadPublic = EventType.pick({
|
|
id: true,
|
|
title: true,
|
|
slug: true,
|
|
length: true,
|
|
hidden: true,
|
|
position: true,
|
|
userId: true,
|
|
teamId: true,
|
|
eventName: true,
|
|
timeZone: true,
|
|
periodType: true,
|
|
periodStartDate: true,
|
|
periodEndDate: true,
|
|
periodDays: true,
|
|
periodCountCalendarDays: true,
|
|
requiresConfirmation: true,
|
|
recurringEvent: true,
|
|
disableGuests: true,
|
|
hideCalendarNotes: true,
|
|
minimumBookingNotice: true,
|
|
beforeEventBuffer: true,
|
|
afterEventBuffer: true,
|
|
schedulingType: true,
|
|
price: true,
|
|
currency: true,
|
|
slotInterval: true,
|
|
successRedirectUrl: true,
|
|
description: true,
|
|
locations: true,
|
|
metadata: true,
|
|
seatsPerTimeSlot: true,
|
|
seatsShowAttendees: true,
|
|
}).merge(
|
|
z.object({
|
|
locations: z
|
|
.array(
|
|
z.object({
|
|
link: z.string().optional(),
|
|
address: z.string().optional(),
|
|
hostPhoneNumber: z.string().optional(),
|
|
type: z.any().optional(),
|
|
})
|
|
)
|
|
.nullable(),
|
|
metadata: jsonSchema.nullable(),
|
|
customInputs: customInputSchema.array().optional(),
|
|
})
|
|
);
|