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.

Filter the partner earnings count by commission type

Rafic56c3bfc3445
diff --git a/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts b/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts
index 95f82c7e00..71e6b05277 100644
--- a/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts
+++ b/apps/web/lib/api/partner-profile/get-partner-earnings-count.ts
@@ -18,6 +18,7 @@ export async function getPartnerEarningsCount({
}) {
const {
groupBy,
+ type,
status,
linkId,
customerId,
@@ -54,6 +55,7 @@ export async function getPartnerEarningsCount({
const count = await prisma.commission.count({
where: {
...where,
+ ...(type && { type }),
...(status && { status }),
...(linkId && { linkId }),
...(customerId && { customerId }),
@@ -65,6 +67,7 @@ export async function getPartnerEarningsCount({
const groupedWhere: Prisma.CommissionWhereInput = {
...where,
+ ...(type && groupBy !== "type" && { type }),
...(status && groupBy !== "status" && { status }),
...(linkId && groupBy !== "linkId" && { linkId }),
...(customerId && groupBy !== "customerId" && { customerId }),
diff --git a/apps/web/playwright/api/partner-profile/earnings.spec.ts b/apps/web/playwright/api/partner-profile/earnings.spec.ts
index 27954d9b5f..e70a115d1e 100644
--- a/apps/web/playwright/api/partner-profile/earnings.spec.ts
+++ b/apps/web/playwright/api/partner-profile/earnings.spec.ts
@@ -126,6 +126,18 @@ test.describe("GET /partner-profile/earnings", () => {
});
});
+ test("counts only the requested commission type", async ({ playwright }) => {
+ await withPartnerApi(playwright, async (partnerApi) => {
+ expect(
+ await partnerApi.get("/api/partner-profile/earnings/count?type=custom"),
+ ).toMatchObject({ status: 200, data: { count: 2 } });
+
+ expect(
+ await partnerApi.get("/api/partner-profile/earnings/count?type=sale"),
+ ).toMatchObject({ status: 200, data: { count: 0 } });
+ });
+ });
+
test("filters by program ID or slug", async ({ playwright, program }) => {
await withPartnerApi(playwright, async (partnerApi) => {
for (const programIdOrSlug of [program.id, programSlug]) {