From f31b84c69d17476fd7533d1bc3b58b4791bb54a8 Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Fri, 19 Sep 2025 15:39:50 -0700 Subject: [PATCH] Improve support for custom commissions in payouts cron --- .../(ee)/api/cron/payouts/create-payout.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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 61e8f4f85f3..42db0fcc643 100644 --- a/apps/web/app/(ee)/api/cron/payouts/create-payout.ts +++ b/apps/web/app/(ee)/api/cron/payouts/create-payout.ts @@ -62,18 +62,31 @@ export const createPayout = async ({ const [commissions, clawbacks] = await Promise.all([ // Find all pending commissions - // We only process commissions that were created before the holding period prisma.commission.findMany({ where: { earnings: { gt: 0, }, ...commonWhere, - ...(holdingPeriodDays > 0 && { - createdAt: { - lt: new Date(Date.now() - holdingPeriodDays * 24 * 60 * 60 * 1000), - }, - }), + // If there is a holding period set: + // we only process commissions that were created before the holding period + // but custom commissions are always included + ...(holdingPeriodDays > 0 + ? { + OR: [ + { + type: "custom", + }, + { + createdAt: { + lt: new Date( + Date.now() - holdingPeriodDays * 24 * 60 * 60 * 1000, + ), + }, + }, + ], + } + : {}), }, select: { id: true,