Skip to content

Commit

Permalink
Attempt to fix ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara committed Dec 23, 2024
1 parent 4dc9a7f commit 583a4ad
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 49 deletions.
5 changes: 1 addition & 4 deletions packages/app-store/salesforce/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export const appDataSchema = eventTypeAppCardZod.extend({
.nativeEnum(SalesforceRecordEnum)
.default(SalesforceRecordEnum.CONTACT)
.optional(),
// Another way to define z.boolean().optional() through z.any()
// Required to prevent tsc crash. I have no clue why it started crashing suddenly.
// But we need to improve the schemas of all apps that are combined into apps.schemas.generated.ts
ifFreeEmailDomainSkipOwnerCheck: optionalBooleanOnlyRunTimeValidation,
ifFreeEmailDomainSkipOwnerCheck: z.boolean().optional(),
skipContactCreation: z.boolean().optional(),
createEventOn: z.nativeEnum(SalesforceRecordEnum).default(SalesforceRecordEnum.CONTACT).optional(),
createNewContactUnderAccount: z.boolean().optional(),
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/event-types/getEventTypesByViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ProfileRepository } from "@calcom/lib/server/repository/profile";
import { UserRepository } from "@calcom/lib/server/repository/user";
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
import { teamMetadataSchema } from "@calcom/prisma/zod-utils";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import { EventTypeMetaDataSchemaWithoutApps } from "@calcom/prisma/zod-utils";

import { TRPCError } from "@trpc/server";

Expand Down Expand Up @@ -116,7 +116,7 @@ export const getEventTypesByViewer = async (user: User, filters?: Filters, forRo
})
)
),
metadata: eventType.metadata ? EventTypeMetaDataSchema.parse(eventType.metadata) : null,
metadata: eventType.metadata ? EventTypeMetaDataSchemaWithoutApps.parse(eventType.metadata) : null,
children: await Promise.all(
(eventType.children || []).map(async (c) => ({
...c,
Expand Down
92 changes: 49 additions & 43 deletions packages/prisma/zod-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,49 +72,55 @@ export const RequiresConfirmationThresholdUnits: z.ZodType<UnitTypeLongPlural> =

export const EventTypeAppMetadataSchema = z.object(appDataSchemas).partial();

export const EventTypeMetaDataSchema = z
.object({
smartContractAddress: z.string().optional(),
blockchainId: z.number().optional(),
multipleDuration: z.number().array().optional(),
giphyThankYouPage: z.string().optional(),
apps: EventTypeAppMetadataSchema.optional(),
additionalNotesRequired: z.boolean().optional(),
disableSuccessPage: z.boolean().optional(),
disableStandardEmails: z
.object({
all: z
.object({
host: z.boolean().optional(),
attendee: z.boolean().optional(),
})
.optional(),
confirmation: z
.object({
host: z.boolean().optional(),
attendee: z.boolean().optional(),
})
.optional(),
})
.optional(),
managedEventConfig: z
.object({
unlockedFields: z.custom<{ [k in keyof Omit<Prisma.EventTypeSelect, "id">]: true }>().optional(),
})
.optional(),
requiresConfirmationThreshold: z
.object({
time: z.number(),
unit: RequiresConfirmationThresholdUnits,
})
.optional(),
config: z
.object({
useHostSchedulesForTeamEvent: z.boolean().optional(),
})
.optional(),
bookerLayouts: bookerLayouts.optional(),
})
const _EventTypeMetaDataSchemaWithoutApps = z.object({
smartContractAddress: z.string().optional(),
blockchainId: z.number().optional(),
multipleDuration: z.number().array().optional(),
giphyThankYouPage: z.string().optional(),
additionalNotesRequired: z.boolean().optional(),
disableSuccessPage: z.boolean().optional(),
disableStandardEmails: z
.object({
all: z
.object({
host: z.boolean().optional(),
attendee: z.boolean().optional(),
})
.optional(),
confirmation: z
.object({
host: z.boolean().optional(),
attendee: z.boolean().optional(),
})
.optional(),
})
.optional(),
managedEventConfig: z
.object({
unlockedFields: z.custom<{ [k in keyof Omit<Prisma.EventTypeSelect, "id">]: true }>().optional(),
})
.optional(),
requiresConfirmationThreshold: z
.object({
time: z.number(),
unit: RequiresConfirmationThresholdUnits,
})
.optional(),
config: z
.object({
useHostSchedulesForTeamEvent: z.boolean().optional(),
})
.optional(),
bookerLayouts: bookerLayouts.optional(),
});

export const EventTypeMetaDataSchemaWithoutApps = _EventTypeMetaDataSchemaWithoutApps.nullable();
export const EventTypeMetaDataSchema = _EventTypeMetaDataSchemaWithoutApps
.merge(
z.object({
apps: EventTypeAppMetadataSchema.optional(),
})
)
.nullable();

export type EventTypeMetadata = z.infer<typeof EventTypeMetaDataSchema>;
Expand Down

0 comments on commit 583a4ad

Please sign in to comment.