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.

Respect link-level discount overrides on customer API responses.

Kiran Kcec75d9980c9
diff --git a/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts b/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
index eac163f77b..5d74f7c5ed 100644
--- a/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
+++ b/apps/web/app/(ee)/api/customers/[id]/reattribute/route.ts
@@ -129,7 +129,15 @@ export const POST = withWorkspace(
programId: link.programId,
},
include: {
- link: true,
+ link: {
+ include: {
+ linkReward: {
+ select: {
+ discount: true,
+ },
+ },
+ },
+ },
programEnrollment: {
include: {
partner: true,
diff --git a/apps/web/lib/api/customers/get-customer-or-throw.ts b/apps/web/lib/api/customers/get-customer-or-throw.ts
index 1e044a2c31..5eea7ad9f6 100644
--- a/apps/web/lib/api/customers/get-customer-or-throw.ts
+++ b/apps/web/lib/api/customers/get-customer-or-throw.ts
@@ -30,7 +30,15 @@ export const getCustomerOrThrow = async (
...(includeExpandedFields
? {
include: {
- link: true,
+ link: {
+ include: {
+ linkReward: {
+ select: {
+ discount: true,
+ },
+ },
+ },
+ },
programEnrollment: {
include: {
partner: true,
diff --git a/apps/web/lib/api/customers/transform-customer.ts b/apps/web/lib/api/customers/transform-customer.ts
index 60d61c6c1f..a4191db758 100644
--- a/apps/web/lib/api/customers/transform-customer.ts
+++ b/apps/web/lib/api/customers/transform-customer.ts
@@ -8,7 +8,13 @@ import {
} from "@prisma/client";
export interface CustomerWithLink extends Customer {
- link?: Link | null;
+ link?:
+ | (Link & {
+ linkReward?: {
+ discount?: Discount | null;
+ } | null;
+ })
+ | null;
programEnrollment?:
| (ProgramEnrollment & {
partner: Partner;
@@ -20,13 +26,17 @@ export interface CustomerWithLink extends Customer {
export const transformCustomer = (customer: CustomerWithLink) => {
const programEnrollment = customer.programEnrollment;
+ // Prefer the link discount if it exists, otherwise use the enrollment discount
+ const discount =
+ customer.link?.linkReward?.discount ?? programEnrollment?.discount;
+
return {
...customer,
name: customer.name || customer.email || generateRandomName(),
link: customer.link || undefined,
programId: programEnrollment?.programId || undefined,
partner: programEnrollment?.partner || undefined,
- discount: programEnrollment?.discount || undefined,
+ discount: discount || undefined,
};
};
diff --git a/apps/web/lib/customers/api/get-customers.ts b/apps/web/lib/customers/api/get-customers.ts
index 803665aeb4..16905ee0ad 100644
--- a/apps/web/lib/customers/api/get-customers.ts
+++ b/apps/web/lib/customers/api/get-customers.ts
@@ -93,6 +93,11 @@ export async function getCustomers(filters: GetCustomersInput) {
shortLink: true,
url: true,
programId: true,
+ linkReward: {
+ select: {
+ discount: true,
+ },
+ },
},
},
programEnrollment: {