Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove earnings from /api/partners endpoint #2056

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading