The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor customer API response structure and improve query handling (#3374)
Kiran K3c02d44dd38f
diff --git a/apps/web/app/(ee)/api/customers/route.ts b/apps/web/app/(ee)/api/customers/route.tsindex aaf5599d87..2fc5cdf60a 100644--- a/apps/web/app/(ee)/api/customers/route.ts+++ b/apps/web/app/(ee)/api/customers/route.ts@@ -83,20 +83,26 @@ export const GET = withWorkspace(? {include: {link: {+ select: {+ id: true,+ domain: true,+ key: true,+ shortLink: true,+ url: true,+ programId: true,+ },+ },+ programEnrollment: {include: {- programEnrollment: {- include: {- partner: {- select: {- id: true,- name: true,- email: true,- image: true,- },- },- discount: true,+ partner: {+ select: {+ id: true,+ name: true,+ email: true,+ image: true,},},+ discount: true,},},},diff --git a/apps/web/lib/api/customers/get-customer-or-throw.ts b/apps/web/lib/api/customers/get-customer-or-throw.tsindex dfbf8462b4..816afb062d 100644--- a/apps/web/lib/api/customers/get-customer-or-throw.ts+++ b/apps/web/lib/api/customers/get-customer-or-throw.ts@@ -31,14 +31,11 @@ export const getCustomerOrThrow = async (...(includeExpandedFields? {include: {- link: {+ link: true,+ programEnrollment: {include: {- programEnrollment: {- include: {- partner: true,- discount: true,- },- },+ partner: true,+ discount: true,},},},diff --git a/apps/web/lib/api/customers/transform-customer.ts b/apps/web/lib/api/customers/transform-customer.tsindex ddea2a5253..d798a58cb6 100644--- a/apps/web/lib/api/customers/transform-customer.ts+++ b/apps/web/lib/api/customers/transform-customer.ts@@ -8,21 +8,17 @@ import {} from "@dub/prisma/client";export interface CustomerWithLink extends Customer {- link?:- | (Link & {- programEnrollment?:- | (ProgramEnrollment & {- partner: Partner;- discount?: Discount | null;- })- | null;+ link?: Link | null;+ programEnrollment?:+ | (ProgramEnrollment & {+ partner: Partner;+ discount?: Discount | null;})| null;- discount?: Discount | null;}export const transformCustomer = (customer: CustomerWithLink) => {- const programEnrollment = customer.link?.programEnrollment;+ const programEnrollment = customer.programEnrollment;return {...customer,