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 create-payout.ts

Kiran Kfb8c7c4a742f
diff --git a/apps/web/app/(ee)/api/cron/payouts/create-payout.ts b/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
index 650abfb931..d93dfdcf93 100644
--- a/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
@@ -119,12 +119,20 @@ export const createPayout = async ({
const allCommissions = [...commissions, ...clawbacks];
// earliest commission date
- const periodStart = allCommissions[0].createdAt;
+ const periodStart = allCommissions.reduce(
+ (earliest, commission) =>
+ commission.createdAt < earliest ? commission.createdAt : earliest,
+ allCommissions[0].createdAt,
+ );
// end of the month of the latest commission date
// e.g. if the latest sale is 2024-12-16, the periodEnd should be 2024-12-31
const periodEnd = endOfMonth(
- allCommissions[allCommissions.length - 1].createdAt,
+ allCommissions.reduce(
+ (latest, commission) =>
+ commission.createdAt > latest ? commission.createdAt : latest,
+ allCommissions[0].createdAt,
+ ),
);
await prisma.$transaction(async (tx) => {