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 combine-payouts.ts

Kiran K3f344d03c787
diff --git a/apps/web/scripts/combine-payouts.ts b/apps/web/scripts/combine-payouts.ts
index 696d0f2519..7f076e763d 100644
--- a/apps/web/scripts/combine-payouts.ts
+++ b/apps/web/scripts/combine-payouts.ts
@@ -42,8 +42,22 @@ async function main() {
`Combining ${payoutsToCombine.length} payouts for partner ${partnerId}`,
);
- const periodStart = payoutsToCombine[0].periodStart;
- const periodEnd = payoutsToCombine[payoutsToCombine.length - 1].periodEnd;
+ const periodStart = payoutsToCombine.reduce(
+ (earliest, payout) =>
+ payout.periodStart && earliest && payout.periodStart < earliest
+ ? payout.periodStart
+ : earliest,
+ payoutsToCombine[0].periodStart || new Date(),
+ );
+
+ const periodEnd = payoutsToCombine.reduce(
+ (latest, payout) =>
+ payout.periodEnd && latest && payout.periodEnd > latest
+ ? payout.periodEnd
+ : latest,
+ payoutsToCombine[0].periodEnd || new Date(),
+ );
+
const totalAmount = payoutsToCombine.reduce(
(sum, payout) => sum + payout.amount,
0,