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.

final changes

Steven Tey5caac10f88d6
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/earnings/count/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/earnings/count/route.ts
index 87a1d351df..df9120e8f4 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/earnings/count/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/earnings/count/route.ts
@@ -17,7 +17,7 @@ export const GET = withPartnerProfile(
const {
groupBy,
- type = "sale",
+ type,
status,
linkId,
customerId,
@@ -26,6 +26,7 @@ export const GET = withPartnerProfile(
start,
end,
} = getPartnerEarningsCountQuerySchema.parse(searchParams);
+
const { startDate, endDate } = getStartEndDates({
interval,
start,
@@ -33,9 +34,32 @@ export const GET = withPartnerProfile(
});
const where: Prisma.CommissionWhereInput = {
+ ...(type
+ ? {
+ type,
+ ...(type === "sale" && {
+ amount: {
+ gt: 0,
+ },
+ }),
+ }
+ : {
+ OR: [
+ {
+ type: "sale",
+ amount: {
+ gt: 0,
+ },
+ },
+ {
+ type: {
+ not: "sale",
+ },
+ },
+ ],
+ }),
programId: program.id,
partnerId: partner.id,
- ...(type && { type }),
...(payoutId && { payoutId }),
createdAt: {
gte: startDate.toISOString(),
@@ -111,6 +135,8 @@ export const GET = withPartnerProfile(
},
});
+ console.log("count", count, where);
+
return NextResponse.json({ count });
}
},
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 f1df2c9860..a81b5de9d0 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,22 +41,32 @@ export const GET = withPartnerProfile(
const earnings = await prisma.commission.findMany({
where: {
- OR: [
- {
- type: "sale",
- amount: {
- gt: 0,
- },
- },
- {
- type: {
- not: "sale",
- },
- },
- ],
+ ...(type
+ ? {
+ type,
+ ...(type === "sale" && {
+ amount: {
+ gt: 0,
+ },
+ }),
+ }
+ : {
+ OR: [
+ {
+ type: "sale",
+ amount: {
+ gt: 0,
+ },
+ },
+ {
+ type: {
+ not: "sale",
+ },
+ },
+ ],
+ }),
programId: program.id,
partnerId: partner.id,
- type,
status,
linkId,
customerId,
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/earnings/timeseries/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/earnings/timeseries/route.ts
index be92b70d6b..eab82bb6a5 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/earnings/timeseries/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/earnings/timeseries/route.ts
@@ -50,11 +50,14 @@ export const GET = withPartnerProfile(
SUM(earnings) AS earnings
FROM Commission
WHERE
- amount > 0
- AND createdAt >= ${startDate}
- AND createdAt < ${endDate}
+ (
+ (type = 'sale' AND amount > 0)
+ OR type != 'sale'
+ )
AND programId = ${program.id}
AND partnerId = ${partner.id}
+ AND createdAt >= ${startDate}
+ AND createdAt < ${endDate}
${type ? Prisma.sql`AND type = ${type}` : Prisma.sql``}
${payoutId ? Prisma.sql`AND payoutId = ${payoutId}` : Prisma.sql``}
${linkId ? Prisma.sql`AND linkId = ${linkId}` : Prisma.sql``}
diff --git a/apps/web/lib/swr/use-partner-earnings-count.ts b/apps/web/lib/swr/use-partner-earnings-count.ts
index ffd76b00ed..7c4f241986 100644
--- a/apps/web/lib/swr/use-partner-earnings-count.ts
+++ b/apps/web/lib/swr/use-partner-earnings-count.ts
@@ -24,6 +24,7 @@ export default function usePartnerEarningsCount<T>(opts?: {
opts,
{
include: [
+ "type",
"linkId",
"customerId",
"status",