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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Sep 19, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Custom commissions are now always considered for pending and scheduled payouts during a holding period, preventing unintended delays.
    • Standard commissions continue to respect the configured holding period; if the holding period is zero, date-based filtering is not applied.
    • Users may see updated pending amounts and earlier inclusion of custom commissions.
    • No changes to clawbacks, payout creation, or aggregation.

@vercel
Copy link
Contributor

vercel bot commented Sep 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 19, 2025 10:44pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Adjusted the pending commissions filter in the payouts cron to always include custom commissions during holding periods by using an OR condition. When holdingPeriodDays > 0, the query includes type="custom" OR createdAt before threshold; otherwise, no date filter is applied. Updated inline comments accordingly. No changes to clawbacks, payout creation, or aggregation logic.

Changes

Cohort / File(s) Summary
Payouts cron filter update
apps/web/app/(ee)/api/cron/payouts/create-payout.ts
Revised pending commissions query: when holdingPeriodDays > 0 apply OR(type == "custom" OR createdAt < threshold) instead of unconditional date filter; when no holding period, omit date filter. Updated inline comments. No changes to exported declarations, clawbacks, payout creation, or aggregation.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Cron as Cron (payouts)
    participant Service as CreatePayout Handler
    participant DB as DB (commissions)
    participant Aggregator as Aggregation/Creation

    Cron->>Service: Trigger create-payout
    alt holdingPeriodDays > 0
        Service->>DB: Query pending commissions<br/>WHERE status = pending AND (type = "custom" OR createdAt < threshold)
        note right of DB #DDEFEF: Custom commissions always included during holding period
    else No holding period
        Service->>DB: Query pending commissions<br/>WHERE status = pending (no date filter)
    end
    Service->>Aggregator: Aggregate eligible commissions
    Aggregator-->>Service: Payout data
    Service-->>Cron: Create payout result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A whisk of code, a twitching ear,
Custom coins hop in, loud and clear.
Hold the line? Not for these—
They leap the hedge with rabbit ease.
Nightly cron, soft paws tread—
Payouts bloom where logic led. 🐇💸

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Improve support for custom commissions in payouts cron" succinctly and accurately describes the main change in the diff: the payouts cron now treats "custom" commission types specially when a holding period is active (adjusting the createdAt filter), which matches the raw_summary. It is concise, specific to the affected area, and informative enough for a reviewer scanning PR history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch payouts-cron-custom

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e9cbd2 and f31b84c.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/payouts/create-payout.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: api-tests
🔇 Additional comments (2)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts (2)

71-89: Logic enhancement improves custom commission handling during holding periods.

The updated logic correctly ensures that custom commissions are always included regardless of holding period restrictions, while regular commissions still respect the holding period threshold. This approach aligns with common affiliate payout practices where holding periods protect against refunds and chargebacks but custom commissions may need different treatment.

The OR condition implementation is clean and the inline comments accurately describe the behavior.


74-89: Verified — 'custom' commissions are intentionally special-cased and bypass the holding period

The codebase consistently treats type: "custom" as manual/one‑time commissions (creation, UI, and migration logic), so including { type: "custom" } in the payout query aligns with existing behavior.

Key locations:

  • apps/web/app/(ee)/api/cron/payouts/create-payout.ts (current change)
  • apps/web/lib/actions/partners/create-manual-commission.ts
  • apps/web/lib/actions/partners/mark-commission-fraud-or-canceled.ts
  • apps/web/scripts/migrations/backfill-commissions-rewardId.ts (excludes custom during backfill)
  • apps/web/ui/partners/commission-row-menu.tsx
  • packages/email/src/templates/new-commission-alert-partner.tsx
  • apps/web/lib/api/workflows/execute-award-bounty-action.ts

No changes required if the intent is to pay manual/custom commissions immediately; otherwise restrict the OR to specific custom subtypes or add an explicit guard.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steven-tey
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts (2)

81-85: Use date-fns subDays and make boundary inclusive.

Clearer and less error‑prone than manual ms math; inclusive lte avoids millisecond edge misses.

-                  createdAt: {
-                    lt: new Date(
-                      Date.now() - holdingPeriodDays * 24 * 60 * 60 * 1000,
-                    ),
-                  },
+                  createdAt: {
+                    lte: subDays(new Date(), holdingPeriodDays),
+                  },

And update imports:

-import { endOfMonth } from "date-fns";
+import { endOfMonth, subDays } from "date-fns";

76-87: Heads‑up: OR may reduce index selectivity; consider split query if this path gets hot.

Two targeted queries can leverage indexes better:

  • Q1: non‑custom, createdAt <= threshold
  • Q2: custom (no date filter)
    Then merge and sort in memory (sets are disjoint if Q1 excludes custom).

Only worth it if this query shows up in profiles.

Would you like a follow‑up patch or schema index suggestions (e.g., composite index on (programId, partnerId, status, payoutId, earnings, createdAt) plus partial index for type='custom')?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e9cbd2 and f31b84c.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/payouts/create-payout.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts (2)

74-89: Custom commissions bypass holding period — change looks correct.

The OR condition correctly includes type="custom" regardless of createdAt when holdingPeriodDays > 0. Matches the PR objective without impacting clawbacks logic.


78-79: Verify Prisma field type and prefer enum symbol

apps/web/app/(ee)/api/cron/payouts/create-payout.ts (line 78) uses type: "custom" while other places use CommissionType.custom. The verification run did not locate a Commission model or CommissionType enum in packages/prisma/schema/schema.prisma — confirm whether Commission.type is an enum; if so, use CommissionType.custom (or ensure the literal exactly matches the Prisma enum value).

@steven-tey steven-tey merged commit 815dae1 into main Sep 19, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the payouts-cron-custom branch September 19, 2025 22:48
@coderabbitai coderabbitai bot mentioned this pull request Oct 6, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants