Scheduling infrastructure for absolutely everyone.
Fix: #8528 Moved the data checks to superRefine (#8749)
Shivang Sharmab552bf69569a
diff --git a/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.handler.ts b/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.handler.tsindex 8e65440eedc..fcaf642d0b6 100644--- a/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.handler.ts+++ b/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.handler.ts@@ -1,6 +1,7 @@import stripe from "@calcom/app-store/stripepayment/lib/server";import type { TStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";+import { ZStripeCheckoutSessionInputSchema } from "./stripeCheckoutSession.schema";type StripeCheckoutSessionOptions = {input: TStripeCheckoutSessionInputSchema;@@ -9,14 +10,9 @@ type StripeCheckoutSessionOptions = {export const stripeCheckoutSessionHandler = async ({ input }: StripeCheckoutSessionOptions) => {const { checkoutSessionId, stripeCustomerId } = input;- // TODO: Move the following data checks to superRefine- if (!checkoutSessionId && !stripeCustomerId) {- throw new Error("Missing checkoutSessionId or stripeCustomerId");- }+ // Moved the following data checks to superRefine+ const validationResult = ZStripeCheckoutSessionInputSchema.parse(input);- if (checkoutSessionId && stripeCustomerId) {- throw new Error("Both checkoutSessionId and stripeCustomerId provided");- }let customerId: string;let isPremiumUsername = false;let hasPaymentFailed = false;diff --git a/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.schema.ts b/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.schema.tsindex 5e307112f23..db054fe2ab9 100644--- a/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.schema.ts+++ b/packages/trpc/server/routers/publicViewer/stripeCheckoutSession.schema.ts@@ -1,8 +1,23 @@import { z } from "zod";-export const ZStripeCheckoutSessionInputSchema = z.object({- stripeCustomerId: z.string().optional(),- checkoutSessionId: z.string().optional(),-});+export const ZStripeCheckoutSessionInputSchema = z+ .object({+ stripeCustomerId: z.string().optional(),+ checkoutSessionId: z.string().optional(),+ })+ .superRefine((arg, ctx) => {+ if (!arg.checkoutSessionId && !arg.stripeCustomerId) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: "Missing checkoutSessionId or stripeCustomerId",+ });+ }+ if (arg.checkoutSessionId && arg.stripeCustomerId) {+ ctx.addIssue({+ code: z.ZodIssueCode.custom,+ message: "Both checkoutSessionId and stripeCustomerId provided",+ });+ }+ });export type TStripeCheckoutSessionInputSchema = z.infer<typeof ZStripeCheckoutSessionInputSchema>;