Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions apps/web/app/(ee)/api/cron/payouts/create-payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down