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

Kiran Kbe991dfa29ae
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
index 906657f33f..92bd3b37bf 100644
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
@@ -2,9 +2,6 @@ import { createId } from "@/lib/api/create-id";
import { prisma } from "@dub/prisma";
import { Program } from "@prisma/client";
-// If the user wants to exclude the current month, we need to split the payouts
-// 1 - one for everything up until the end of the previous month
-// 2 - everything else in the current month will be left as pending (and excluded from the payout)
export async function splitPayouts({
program,
}: {
@@ -61,6 +58,9 @@ export async function splitPayouts({
const previousCommissionsCount = previousCommissions.length;
const currentCommissionsCount = currentCommissions.length;
+ // If there are previous commissions, we need to split the payout into two
+ // 1 - one for everything up until the end of the previous month
+ // 2 - everything else in the current month will be left as pending (and excluded from the payout)
if (previousCommissionsCount > 0) {
const periodEnd =
previousCommissions[previousCommissionsCount - 1].createdAt;
@@ -115,5 +115,18 @@ export async function splitPayouts({
});
}
}
+
+ // If there are no previous commissions, we need to update the existing payout start date
+ // so that it will be excluded from the current month's payout
+ else {
+ await prisma.payout.update({
+ where: {
+ id: payout.id,
+ },
+ data: {
+ periodStart: currentCommissions[0].createdAt,
+ },
+ });
+ }
}
}