From 37069e2d7b4d00046a351ad2a1cda999c03ec8df Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Wed, 18 May 2022 20:22:43 +0200 Subject: [PATCH] fix: omit metadata/locations and rewrite as json --- lib/types.ts | 14 +++++++------- lib/validations/event-type.ts | 6 ++++-- pages/api/event-types/[id].ts | 2 +- pages/api/event-types/index.ts | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/types.ts b/lib/types.ts index 58d4b17a9c..574e164e29 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -124,17 +124,17 @@ export type EventTypeCustomInputResponse = BaseResponse & { export type EventTypeCustomInputsResponse = BaseResponse & { event_type_custom_inputs?: Partial[]; }; -export type EventTypeWithMetadataLocations = EventType & { - locations?: object; - metadata?: object; - recurringEvent?: object; -}; +export interface EventTypeMeta extends Omit { + locations?: JSON; + metadata?: JSON; + recurringEvent: JSON; +} // EventType export type EventTypeResponse = BaseResponse & { - event_type?: Partial; + event_type?: Partial; }; export type EventTypesResponse = BaseResponse & { - event_types?: Partial[]; + event_types?: Partial[]; }; // Payment diff --git a/lib/validations/event-type.ts b/lib/validations/event-type.ts index 2eb3d88774..6b43a4474a 100644 --- a/lib/validations/event-type.ts +++ b/lib/validations/event-type.ts @@ -38,8 +38,8 @@ const schemaEventTypeCreateParams = z slug: z.string(), description: z.string().optional().nullable(), length: z.number().int(), - // locations: jsonSchema.optional().nullable().or(z.null()), - // metadata: z.any().optional().nullable().or(z.null()), + locations: jsonSchema.optional().nullable().or(z.null()), + metadata: z.any().optional().nullable().or(z.null()), recurringEvent: jsonSchema.optional().nullable().or(z.null()), }) .strict(); @@ -85,4 +85,6 @@ export const schemaEventTypeReadPublic = EventType.pick({ slotInterval: true, successRedirectUrl: true, description: true, + locations: true, + metadata: true, }); diff --git a/pages/api/event-types/[id].ts b/pages/api/event-types/[id].ts index 19ca5e0cbb..6319b48b9e 100644 --- a/pages/api/event-types/[id].ts +++ b/pages/api/event-types/[id].ts @@ -55,7 +55,7 @@ export async function eventTypeById( case "GET": await prisma.eventType .findUnique({ where: { id: safeQuery.data.id } }) - // .then((data) => schemaEventTypeReadPublic.parse(data)) + .then((data) => schemaEventTypeReadPublic.parse(data)) .then((event_type) => res.status(200).json({ event_type })) .catch((error: Error) => res.status(404).json({ diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index 4570934b17..163fa501fb 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -30,8 +30,8 @@ async function createOrlistAllEventTypes( * description: No event types were found */ const data = await prisma.eventType.findMany({ where: { userId } }); - // const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); - if (data) res.status(200).json({ event_types: data }); + const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); + if (event_types) res.status(200).json({ event_types }); else (error: Error) => res.status(404).json({