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.

Update route.ts

Kiran K28d715ded2f8
diff --git a/apps/web/app/(ee)/api/programs/[programId]/payouts/count/route.ts b/apps/web/app/(ee)/api/programs/[programId]/payouts/count/route.ts
index d2e6d1611b..b9d80287b5 100644
--- a/apps/web/app/(ee)/api/programs/[programId]/payouts/count/route.ts
+++ b/apps/web/app/(ee)/api/programs/[programId]/payouts/count/route.ts
@@ -77,34 +77,62 @@ export const GET = withWorkspace(
}
// Special case for excludeCurrentMonth on the payout invoice sheet
- const commissions = await prisma.commission.groupBy({
- by: ["payoutId"],
- where: {
- programId,
- payout: {
+ const [commissions, customPayouts] = await Promise.all([
+ prisma.commission.groupBy({
+ by: ["payoutId"],
+ where: {
+ programId,
+ payout: {
+ amount: {
+ gte: minPayoutAmount,
+ },
+ },
+ partner: {
+ payoutsEnabledAt: {
+ not: null,
+ },
+ },
+ status: "processed",
+ createdAt: {
+ lt: currentMonthStart,
+ },
+ },
+ _sum: {
+ earnings: true,
+ },
+ }),
+
+ prisma.payout.aggregate({
+ where: {
+ programId,
amount: {
gte: minPayoutAmount,
},
- },
- partner: {
- payoutsEnabledAt: {
- not: null,
+ partner: {
+ payoutsEnabledAt: {
+ not: null,
+ },
},
+ status: "pending",
+ periodStart: null,
+ periodEnd: null,
+ // createdAt: {
+ // lt: currentMonthStart,
+ // },
},
- status: "processed",
- createdAt: {
- lt: currentMonthStart,
+ _sum: {
+ amount: true,
},
- },
- _sum: {
- earnings: true,
- },
- });
+ _count: true,
+ }),
+ ]);
const counts = {
status: "pending",
- count: commissions.length,
- amount: commissions.reduce((acc, c) => acc + (c._sum.earnings ?? 0), 0),
+ count: commissions.length + customPayouts._count,
+ amount:
+ commissions.reduce((acc, c) => acc + (c._sum.earnings ?? 0), 0) +
+ (customPayouts._sum.amount ?? 0),
};
return NextResponse.json([counts]);