Skip to content

Commit

Permalink
Remove earnings from /api/partners endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
devkiran committed Feb 20, 2025
1 parent 6aedb59 commit c4f4c50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
42 changes: 17 additions & 25 deletions apps/web/app/api/partners/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,32 @@ export const GET = withWorkspace(
pe.partnerId,
pe.tenantId,
pe.createdAt as enrollmentCreatedAt,
COALESCE(SUM(DISTINCT l.clicks), 0) as totalClicks,
COALESCE(SUM(DISTINCT l.leads), 0) as totalLeads,
COALESCE(SUM(DISTINCT l.sales), 0) as totalSales,
COALESCE(SUM(c.amount), 0) as totalSaleAmount,
COALESCE(SUM(c.earnings), 0) as totalEarnings,
(
SELECT JSON_ARRAYAGG(
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,
JSON_ARRAYAGG(
IF(l.id IS NOT NULL,
JSON_OBJECT(
'id', l2.id,
'domain', l2.domain,
'key', l2.key,
'shortLink', l2.shortLink,
'url', l2.url,
'clicks', CAST(l2.clicks AS SIGNED),
'leads', CAST(l2.leads AS SIGNED),
'sales', CAST(l2.sales AS SIGNED),
'saleAmount', CAST(l2.saleAmount AS SIGNED)
)
'id', l.id,
'domain', l.domain,
'key', l.key,
'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
)
FROM (
SELECT DISTINCT l.id, l.domain, l.key, l.shortLink, l.url, l.clicks, l.leads, l.sales, l.saleAmount
FROM Link l
WHERE l.programId = pe.programId AND l.partnerId = pe.partnerId
) l2
) as links
FROM
ProgramEnrollment pe
INNER JOIN
Partner p ON p.id = pe.partnerId
LEFT JOIN
Link l ON l.programId = pe.programId AND l.partnerId = pe.partnerId
LEFT JOIN
Commission c ON c.linkId = l.id
WHERE
pe.programId = ${program.id}
${status ? Prisma.sql`AND pe.status = ${status}` : Prisma.sql`AND pe.status != 'rejected'`}
Expand All @@ -119,7 +112,6 @@ export const GET = withWorkspace(
leads: Number(partner.totalLeads),
sales: Number(partner.totalSales),
saleAmount: Number(partner.totalSaleAmount),
earnings: Number(partner.totalEarnings),
links: partner.links.filter((link: any) => link !== null),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ export function PartnerTable() {
})
: "-",
},
{
id: "earnings",
header: "Earnings",
accessorFn: (d) =>
d.status !== "pending"
? currencyFormatter(d.earnings / 100, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
: "-",
},
// Menu
{
id: "menu",
Expand All @@ -206,14 +195,7 @@ export function PartnerTable() {
onPaginationChange: setPagination,
columnVisibility,
onColumnVisibilityChange: setColumnVisibility,
sortableColumns: [
"createdAt",
"clicks",
"leads",
"sales",
"saleAmount",
"earnings",
],
sortableColumns: ["createdAt", "clicks", "leads", "sales", "saleAmount"],
sortBy,
sortOrder,
onSortChange: ({ sortBy, sortOrder }) =>
Expand Down

0 comments on commit c4f4c50

Please sign in to comment.