More comments

pull/6560/head
Hariom Balhara 2023-02-16 12:08:22 +05:30
parent ef85718ae8
commit c5cd57d8f4
2 changed files with 23 additions and 15 deletions

View File

@ -49,7 +49,8 @@ import { slugify } from "@calcom/lib/slugify";
import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager"; import { updateWebUser as syncServicesUpdateWebUser } from "@calcom/lib/sync/SyncServiceManager";
import prisma, { userSelect } from "@calcom/prisma"; import prisma, { userSelect } from "@calcom/prisma";
import { import {
bookingCreateSchemaForApiOnly, bookingCreateBodySchemaForApi,
bookingCreateSchemaLegacyPropsForApi,
customInputSchema, customInputSchema,
EventTypeMetaDataSchema, EventTypeMetaDataSchema,
extendedBookingCreateBody, extendedBookingCreateBody,
@ -330,7 +331,7 @@ function getBookingData({
}), }),
}) })
) )
: extendedBookingCreateBody.merge(bookingCreateSchemaForApiOnly); : bookingCreateBodySchemaForApi;
const reqBody = bookingDataSchema.parse(req.body); const reqBody = bookingDataSchema.parse(req.body);
if ("responses" in reqBody) { if ("responses" in reqBody) {
@ -372,7 +373,7 @@ function getBookingData({
function getCustomInputsResponses( function getCustomInputsResponses(
reqBody: { reqBody: {
responses?: Record<string, any>; responses?: Record<string, any>;
customInputs?: z.infer<typeof bookingCreateSchemaForApiOnly>["customInputs"]; customInputs?: z.infer<typeof bookingCreateSchemaLegacyPropsForApi>["customInputs"];
}, },
eventTypeCustomInputs: Awaited<ReturnType<typeof getEventTypesFromDB>>["customInputs"] eventTypeCustomInputs: Awaited<ReturnType<typeof getEventTypesFromDB>>["customInputs"]
) { ) {
@ -1359,7 +1360,7 @@ async function handler(
try { try {
await scheduleWorkflowReminders( await scheduleWorkflowReminders(
eventType.workflows, eventType.workflows,
smsReminderNumber as string | null, smsReminderNumber || null,
{ ...evt, ...{ metadata } }, { ...evt, ...{ metadata } },
evt.requiresConfirmation || false, evt.requiresConfirmation || false,
rescheduleUid ? true : false, rescheduleUid ? true : false,

View File

@ -143,16 +143,6 @@ export const stringOrNumber = z.union([
export const stringToDayjs = z.string().transform((val) => dayjs(val)); export const stringToDayjs = z.string().transform((val) => dayjs(val));
export const bookingCreateSchemaForApiOnly = z.object({
name: z.string(),
email: z.string(),
location: z.string().optional(),
guests: z.array(z.string()).optional(),
notes: z.string().optional(),
rescheduleReason: z.string().optional(),
customInputs: z.array(z.object({ label: z.string(), value: z.union([z.string(), z.boolean()]) })),
});
export const bookingCreateBodySchema = z.object({ export const bookingCreateBodySchema = z.object({
end: z.string(), end: z.string(),
eventTypeId: z.number(), eventTypeId: z.number(),
@ -186,13 +176,13 @@ export const bookingConfirmPatchBodySchema = z.object({
reason: z.string().optional(), reason: z.string().optional(),
}); });
// `responses` is merged with it during handleNewBooking call because `responses` schema is dynamic and depends on eventType
export const extendedBookingCreateBody = bookingCreateBodySchema.merge( export const extendedBookingCreateBody = bookingCreateBodySchema.merge(
z.object({ z.object({
noEmail: z.boolean().optional(), noEmail: z.boolean().optional(),
recurringCount: z.number().optional(), recurringCount: z.number().optional(),
allRecurringDates: z.string().array().optional(), allRecurringDates: z.string().array().optional(),
currentRecurringIndex: z.number().optional(), currentRecurringIndex: z.number().optional(),
smsReminderNumber: z.string().optional().nullable(),
appsStatus: z appsStatus: z
.array( .array(
z.object({ z.object({
@ -208,6 +198,23 @@ export const extendedBookingCreateBody = bookingCreateBodySchema.merge(
}) })
); );
// It has only the legacy props that are part of `responses` now. The API can still hit old props
export const bookingCreateSchemaLegacyPropsForApi = z.object({
email: z.string(),
name: z.string(),
guests: z.array(z.string()).optional(),
notes: z.string().optional(),
location: z.string().optional(),
smsReminderNumber: z.string().optional().nullable(),
rescheduleReason: z.string().optional(),
customInputs: z.array(z.object({ label: z.string(), value: z.union([z.string(), z.boolean()]) })),
});
// This is the schema that is used for the API. It has all the legacy props that are part of `responses` now.
export const bookingCreateBodySchemaForApi = extendedBookingCreateBody.merge(
bookingCreateSchemaLegacyPropsForApi
);
export const schemaBookingCancelParams = z.object({ export const schemaBookingCancelParams = z.object({
id: z.number().optional(), id: z.number().optional(),
uid: z.string().optional(), uid: z.string().optional(),