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.

final fixes

Steven Teyecf07ab3e546
diff --git a/apps/web/app/(ee)/api/customers/route.ts b/apps/web/app/(ee)/api/customers/route.ts
index 52c04fafda..54a61c910d 100644
--- a/apps/web/app/(ee)/api/customers/route.ts
+++ b/apps/web/app/(ee)/api/customers/route.ts
@@ -118,27 +118,6 @@ export const GET = withWorkspace(
: {}),
})) as CustomerResponse[];
- const discounts: Map<string, Discount | null> = new Map();
-
- if (includeExpandedFields) {
- const firstPurchases = await prisma.commission.findMany({
- where: {
- customerId: {
- in: customers.map((customer) => customer.id),
- },
- type: "sale",
- },
- select: {
- customerId: true,
- createdAt: true,
- },
- orderBy: {
- createdAt: "asc",
- },
- distinct: ["customerId"],
- });
- }
-
const responseSchema = includeExpandedFields
? CustomerEnrichedSchema.merge(
z.object({
@@ -147,9 +126,11 @@ export const GET = withWorkspace(
)
: CustomerSchema;
- return NextResponse.json(
- responseSchema.array().parse(customers.map(transformCustomer)),
- );
+ const response = responseSchema
+ .array()
+ .parse(customers.map(transformCustomer));
+
+ return NextResponse.json(response);
},
{
requiredPlan: [
diff --git a/apps/web/lib/api/customers/transform-customer.ts b/apps/web/lib/api/customers/transform-customer.ts
index e57414e768..a90e1a2e75 100644
--- a/apps/web/lib/api/customers/transform-customer.ts
+++ b/apps/web/lib/api/customers/transform-customer.ts
@@ -33,5 +33,9 @@ export const transformCustomer = (customer: CustomerWithLink) => {
link: customer.link || undefined,
programId: programEnrollment?.programId || undefined,
partner: programEnrollment?.partner || undefined,
+ discount:
+ programEnrollment?.discount ||
+ programEnrollment?.program?.defaultDiscount ||
+ undefined,
};
};