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 K232bd9e59797
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.ts
index 394fb77730..f8f169434d 100644
--- a/apps/web/app/api/customers/[id]/route.ts
+++ b/apps/web/app/api/customers/[id]/route.ts
@@ -27,9 +27,11 @@ export const GET = withWorkspace(
{ includeExpandedFields },
);
- return NextResponse.json(
- CustomerEnrichedSchema.parse(transformCustomer(customer)),
- );
+ const responseSchema = includeExpandedFields
+ ? CustomerEnrichedSchema
+ : CustomerSchema;
+
+ return NextResponse.json(responseSchema.parse(transformCustomer(customer)));
},
{
requiredPlan: [
@@ -82,8 +84,12 @@ export const PATCH = withWorkspace(
: {}),
});
+ const responseSchema = includeExpandedFields
+ ? CustomerEnrichedSchema
+ : CustomerSchema;
+
return NextResponse.json(
- CustomerSchema.parse(transformCustomer(updatedCustomer)),
+ responseSchema.parse(transformCustomer(updatedCustomer)),
);
} catch (error) {
if (error.code === "P2002") {
diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.ts
index 97bff34dd8..28e46848b0 100644
--- a/apps/web/app/api/customers/route.ts
+++ b/apps/web/app/api/customers/route.ts
@@ -46,8 +46,12 @@ export const GET = withWorkspace(
: {}),
});
+ const responseSchema = includeExpandedFields
+ ? CustomerEnrichedSchema
+ : CustomerSchema;
+
return NextResponse.json(
- CustomerEnrichedSchema.array().parse(customers.map(transformCustomer)),
+ responseSchema.array().parse(customers.map(transformCustomer)),
);
},
{
diff --git a/apps/web/lib/analytics/get-folder-ids-to-filter.ts b/apps/web/lib/analytics/get-folder-ids-to-filter.ts
index a4d9b50623..b322118ee8 100644
--- a/apps/web/lib/analytics/get-folder-ids-to-filter.ts
+++ b/apps/web/lib/analytics/get-folder-ids-to-filter.ts
@@ -12,6 +12,7 @@ export const getFolderIdsToFilter = async ({
if (workspace.foldersUsage === 0) {
return undefined;
}
+
// If the request is not for a specific folder, find folders the user has access to + unsorted folder
let folderIds: string[] | undefined = undefined;
diff --git a/apps/web/lib/api/customers/transform-customer.ts b/apps/web/lib/api/customers/transform-customer.ts
index 760613636c..43a5b1b285 100644
--- a/apps/web/lib/api/customers/transform-customer.ts
+++ b/apps/web/lib/api/customers/transform-customer.ts
@@ -22,11 +22,12 @@ export interface CustomerWithLink extends Customer {
export const transformCustomer = (customer: CustomerWithLink) => {
const programEnrollment = customer.link?.programEnrollment;
+
return {
...customer,
name: customer.name || customer.email || generateRandomName(),
link: customer.link || undefined,
- partner: programEnrollment?.partner || undefined,
- discount: programEnrollment?.discount || undefined,
+ partner: programEnrollment?.partner || null,
+ discount: programEnrollment?.discount || null,
};
};
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 429304f148..8937465e16 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -64,6 +64,7 @@ export const CustomerSchema = z.object({
createdAt: z.date().describe("The date the customer was created."),
});
+// An extended schema that includes the customer's link, partner, and discount.
export const CustomerEnrichedSchema = CustomerSchema.extend({
link: LinkSchema.pick({
id: true,