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.

Fix commission index

Steven Teya78fb82a8a36
diff --git a/apps/web/app/api/embed/referrals/commissions/route.ts b/apps/web/app/api/embed/referrals/commissions/route.ts
index 411ee86f29..3f4d20e906 100644
--- a/apps/web/app/api/embed/referrals/commissions/route.ts
+++ b/apps/web/app/api/embed/referrals/commissions/route.ts
@@ -14,9 +14,19 @@ export const GET = withReferralsEmbedToken(
const commissions = await prisma.commission.findMany({
where: {
- amount: {
- gt: 0,
- },
+ OR: [
+ {
+ type: "sale",
+ amount: {
+ gt: 0,
+ },
+ },
+ {
+ type: {
+ not: "sale",
+ },
+ },
+ ],
programId,
partnerId,
},
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts
index f55c153206..f1df2c9860 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts
@@ -41,9 +41,19 @@ export const GET = withPartnerProfile(
const earnings = await prisma.commission.findMany({
where: {
- amount: {
- gt: 0,
- },
+ OR: [
+ {
+ type: "sale",
+ amount: {
+ gt: 0,
+ },
+ },
+ {
+ type: {
+ not: "sale",
+ },
+ },
+ ],
programId: program.id,
partnerId: partner.id,
type,
diff --git a/apps/web/app/api/partners/analytics/route.ts b/apps/web/app/api/partners/analytics/route.ts
index 025ad11a68..91234c43c3 100644
--- a/apps/web/app/api/partners/analytics/route.ts
+++ b/apps/web/app/api/partners/analytics/route.ts
@@ -89,12 +89,12 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
earnings: true,
},
where: {
+ type: "sale",
amount: {
gt: 0,
},
programId: programEnrollment.programId,
partnerId: programEnrollment.partnerId,
- type: "sale",
status: {
in: ["pending", "processed", "paid"],
},
@@ -164,12 +164,12 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
const topLinkEarnings = await prisma.commission.groupBy({
by: ["linkId"],
where: {
+ type: "sale",
amount: {
gt: 0,
},
programId: programEnrollment.programId,
partnerId: programEnrollment.partnerId,
- type: "sale",
status: {
in: ["pending", "processed", "paid"],
},
diff --git a/apps/web/app/api/programs/[programId]/metrics/route.ts b/apps/web/app/api/programs/[programId]/metrics/route.ts
index 02b257522f..96698eca03 100644
--- a/apps/web/app/api/programs/[programId]/metrics/route.ts
+++ b/apps/web/app/api/programs/[programId]/metrics/route.ts
@@ -35,11 +35,11 @@ export const GET = withWorkspace(
prisma.commission.aggregate({
where: {
+ type: "sale",
amount: {
gt: 0,
},
...where,
- type: "sale",
},
_sum: {
amount: true,
@@ -48,11 +48,11 @@ export const GET = withWorkspace(
prisma.commission.count({
where: {
+ type: "sale",
amount: {
gt: 0,
},
...where,
- type: "sale",
},
}),
diff --git a/apps/web/app/api/programs/[programId]/sales/count/route.ts b/apps/web/app/api/programs/[programId]/sales/count/route.ts
index f9116b3eb5..7388824bb2 100644
--- a/apps/web/app/api/programs/[programId]/sales/count/route.ts
+++ b/apps/web/app/api/programs/[programId]/sales/count/route.ts
@@ -24,12 +24,12 @@ export const GET = withWorkspace(
const salesCount = await prisma.commission.groupBy({
by: ["status"],
where: {
+ type: "sale",
amount: {
gt: 0,
},
programId,
status,
- type: "sale",
partnerId,
payoutId,
customerId,
diff --git a/apps/web/app/api/programs/[programId]/sales/route.ts b/apps/web/app/api/programs/[programId]/sales/route.ts
index 6e5500f683..addf9b6a38 100644
--- a/apps/web/app/api/programs/[programId]/sales/route.ts
+++ b/apps/web/app/api/programs/[programId]/sales/route.ts
@@ -34,13 +34,13 @@ export const GET = withWorkspace(
const sales = await prisma.commission.findMany({
where: {
+ type: "sale",
amount: {
gt: 0,
},
programId,
partnerId,
status,
- type: "sale",
customerId,
payoutId,
createdAt: {
diff --git a/packages/prisma/schema/commission.prisma b/packages/prisma/schema/commission.prisma
index 8cddf3a101..cc0c78b032 100644
--- a/packages/prisma/schema/commission.prisma
+++ b/packages/prisma/schema/commission.prisma
@@ -42,6 +42,7 @@ model Commission {
@@unique([programId, invoiceId])
@@index([amount, programId, partnerId, status, earnings])
+ @@index([type, amount, programId, partnerId, status, earnings])
@@index([partnerId, customerId])
@@index(payoutId)
@@index(customerId)