Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add CustomerEnrichedSchema

Kiran Kd7cab56a51bf
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.ts
index dc8a194f17..394fb77730 100644
--- a/apps/web/app/api/customers/[id]/route.ts
+++ b/apps/web/app/api/customers/[id]/route.ts
@@ -4,6 +4,7 @@ import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import {
+ CustomerEnrichedSchema,
CustomerSchema,
getCustomersQuerySchema,
updateCustomerBodySchema,
@@ -26,7 +27,9 @@ export const GET = withWorkspace(
{ includeExpandedFields },
);
- return NextResponse.json(CustomerSchema.parse(transformCustomer(customer)));
+ return NextResponse.json(
+ CustomerEnrichedSchema.parse(transformCustomer(customer)),
+ );
},
{
requiredPlan: [
diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.ts
index ebc5cba3db..97bff34dd8 100644
--- a/apps/web/app/api/customers/route.ts
+++ b/apps/web/app/api/customers/route.ts
@@ -5,6 +5,7 @@ import { withWorkspace } from "@/lib/auth";
import { generateRandomName } from "@/lib/names";
import {
createCustomerBodySchema,
+ CustomerEnrichedSchema,
CustomerSchema,
getCustomersQuerySchema,
} from "@/lib/zod/schemas/customers";
@@ -46,7 +47,7 @@ export const GET = withWorkspace(
});
return NextResponse.json(
- CustomerSchema.array().parse(customers.map(transformCustomer)),
+ CustomerEnrichedSchema.array().parse(customers.map(transformCustomer)),
);
},
{
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index a1a2174eb7..429304f148 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -2,6 +2,7 @@ import z from "@/lib/zod";
import { DiscountSchema } from "./discount";
import { LinkSchema } from "./links";
import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";
+import { PartnerSchema } from "./partners";
export const getCustomersQuerySchema = z.object({
email: z
@@ -47,7 +48,6 @@ export const createCustomerBodySchema = z.object({
export const updateCustomerBodySchema = createCustomerBodySchema.partial();
-// customer object schema
export const CustomerSchema = z.object({
id: z
.string()
@@ -62,22 +62,23 @@ export const CustomerSchema = z.object({
avatar: z.string().nullish().describe("Avatar URL of the customer."),
country: z.string().nullish().describe("Country of the customer."),
createdAt: z.date().describe("The date the customer was created."),
+});
+
+export const CustomerEnrichedSchema = CustomerSchema.extend({
link: LinkSchema.pick({
id: true,
domain: true,
key: true,
shortLink: true,
programId: true,
- }).nullish(),
- partner: z
- .object({
- id: z.string(),
- name: z.string().nullish(),
- email: z.string().nullish(),
- image: z.string().nullish(),
- })
- .nullish(),
- discount: DiscountSchema.nullish(),
+ }),
+ partner: PartnerSchema.pick({
+ id: true,
+ name: true,
+ email: true,
+ image: true,
+ }),
+ discount: DiscountSchema.nullable(),
});
export const CUSTOMERS_MAX_PAGE_SIZE = 100;