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.

transformCustomerForCommission

Steven Tey7798a39dac70
diff --git a/apps/web/app/(ee)/api/commissions/route.ts b/apps/web/app/(ee)/api/commissions/route.ts
index 815eaef7d2..45f57661a6 100644
--- a/apps/web/app/(ee)/api/commissions/route.ts
+++ b/apps/web/app/(ee)/api/commissions/route.ts
@@ -1,4 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
+import { transformCustomerForCommission } from "@/lib/api/customers/transform-customer";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
@@ -66,6 +67,11 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
});
return NextResponse.json(
- z.array(CommissionEnrichedSchema).parse(commissions),
+ z.array(CommissionEnrichedSchema).parse(
+ commissions.map((c) => ({
+ ...c,
+ customer: transformCustomerForCommission(c.customer),
+ })),
+ ),
);
});
diff --git a/apps/web/lib/api/customers/transform-customer.ts b/apps/web/lib/api/customers/transform-customer.ts
index c1266f2ee2..ddea2a5253 100644
--- a/apps/web/lib/api/customers/transform-customer.ts
+++ b/apps/web/lib/api/customers/transform-customer.ts
@@ -33,3 +33,14 @@ export const transformCustomer = (customer: CustomerWithLink) => {
discount: programEnrollment?.discount || undefined,
};
};
+
+export const transformCustomerForCommission = (customer?: Customer | null) => {
+ if (!customer) {
+ return customer;
+ }
+
+ return {
+ ...customer,
+ name: customer.name || customer.email || generateRandomName(),
+ };
+};