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.

join to retrieve links that belong to the partner+program

Steven Tey3f9153811be7
diff --git a/apps/web/app/api/partners/route.ts b/apps/web/app/api/partners/route.ts
index 2594e08dad..e384c77050 100644
--- a/apps/web/app/api/partners/route.ts
+++ b/apps/web/app/api/partners/route.ts
@@ -68,13 +68,27 @@ export const GET = withWorkspace(
COALESCE(SUM(l.clicks), 0) as totalClicks,
COALESCE(SUM(l.leads), 0) as totalLeads,
COALESCE(SUM(l.sales), 0) as totalSales,
- COALESCE(SUM(l.saleAmount), 0) as totalSaleAmount
+ COALESCE(SUM(l.saleAmount), 0) as totalSaleAmount,
+ JSON_ARRAYAGG(
+ IF(l.id IS NOT NULL,
+ JSON_OBJECT(
+ 'id', l.id,
+ 'shortLink', l.shortLink,
+ 'url', l.url,
+ 'clicks', CAST(l.clicks AS SIGNED),
+ 'leads', CAST(l.leads AS SIGNED),
+ 'sales', CAST(l.sales AS SIGNED),
+ 'saleAmount', CAST(l.saleAmount AS SIGNED)
+ ),
+ NULL
+ )
+ ) as links
FROM
ProgramEnrollment pe
INNER JOIN
Partner p ON p.id = pe.partnerId
LEFT JOIN
- Link l ON l.partnerId = pe.partnerId
+ Link l ON l.partnerId = pe.partnerId AND l.programId = pe.programId
WHERE
pe.programId = ${program.id}
${tenantId ? Prisma.sql`AND pe.tenantId = ${tenantId}` : Prisma.sql``}
@@ -100,7 +114,7 @@ export const GET = withWorkspace(
? partner.totalSaleAmount
: partner.totalSales) ?? 0) *
(program.commissionAmount / 100),
- links: null,
+ links: partner.links.filter((link: any) => link !== null),
}));
return NextResponse.json(z.array(EnrolledPartnerSchema).parse(response));
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 257bbaa1bb..6c88d32171 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -41,7 +41,7 @@ export const createProgramSchema = z.object({
cookieLength: z.number().min(1).max(180),
domain: z.string().nullable(),
url: z.string().nullable(),
-});
+});
export const ProgramEnrollmentSchema = z.object({
partnerId: z.string(),
@@ -53,8 +53,6 @@ export const ProgramEnrollmentSchema = z.object({
LinkSchema.pick({
id: true,
shortLink: true,
- domain: true,
- key: true,
url: true,
clicks: true,
leads: true,