Skip to content

Add paid at to commissions API and export#4048

Open
pepeladeira wants to merge 2 commits into
mainfrom
add-paid-at-commissions-export
Open

Add paid at to commissions API and export#4048
pepeladeira wants to merge 2 commits into
mainfrom
add-paid-at-commissions-export

Conversation

@pepeladeira

@pepeladeira pepeladeira commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Commission entries now include a “Paid at” field indicating when the related payout was completed.
    • The field is returned in API results and included in commission exports.
    • When a commission has no paid payout, “Paid at” is shown as null (and exported as an empty value where applicable).

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jun 16, 2026 9:20pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8203873a-53ed-4ea9-a39c-9b3d90b3018d

📥 Commits

Reviewing files that changed from the base of the PR and between 71423ae and 6697852.

📒 Files selected for processing (4)
  • apps/web/app/(ee)/api/commissions/route.ts
  • apps/web/lib/api/commissions/format-commissions-for-export.ts
  • apps/web/lib/api/commissions/get-commissions.ts
  • apps/web/lib/zod/schemas/commissions.ts

📝 Walkthrough

Walkthrough

Adds paidAt (sourced from payout.paidAt) to the commission data pipeline: the Prisma query now includes the payout relation, CommissionEnrichedSchema exposes a nullable paidAt field, the API route maps it onto each response item, and the export formatter adds it as a date column.

Changes

Commission paidAt field

Layer / File(s) Summary
Schema and export column config
apps/web/lib/zod/schemas/commissions.ts
CommissionEnrichedSchema gains paidAt: z.date().nullish(); COMMISSION_EXPORT_COLUMNS gains a non-default paidAt date column entry.
Prisma fetch and API response mapping
apps/web/lib/api/commissions/get-commissions.ts, apps/web/app/(ee)/api/commissions/route.ts
getCommissions adds payout { select: { paidAt } } to the Prisma include; the GET route maps c.payout?.paidAt ?? null onto each commission before CommissionEnrichedSchema validation.
Export formatter
apps/web/lib/api/commissions/format-commissions-for-export.ts
The date Zod column schema is widened to accept Date | string | null, normalizing to ISO string or empty string; paidAt is added to the formatted row from commission.payout?.paidAt.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • dubinc/dub#3922: Extends the same export pipeline files (format-commissions-for-export.ts, COMMISSION_EXPORT_COLUMNS) to add a different new column (stripeCustomerId).

Suggested reviewers

  • steven-tey

Poem

🐇 A rabbit hopped through the ledger one day,
And found that paidAt had gone astray —
No payout date in the export row?
I'll fetch it from Prisma and let it flow!
Now commissions shine with timestamps bright,
Everything's paid, and everything's right. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: adding the paidAt field to both the commissions API and export functionality.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-paid-at-commissions-export

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.

@pepeladeira

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review. any breaking changes?

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== route.ts ==="
cat apps/web/app/\(ee\)/api/commissions/route.ts

echo ""
echo "=== format-commissions-for-export.ts ==="
cat apps/web/lib/api/commissions/format-commissions-for-export.ts

echo ""
echo "=== get-commissions.ts ==="
cat apps/web/lib/api/commissions/get-commissions.ts

echo ""
echo "=== commissions.ts (schemas) ==="
cat apps/web/lib/zod/schemas/commissions.ts

Length of output: 31097


🏁 Script executed:

#!/bin/bash
echo "=== Find all callers of getCommissions ==="
rg -n "getCommissions" --type=ts -B2 -A2

echo ""
echo "=== Check if payout model/table has paidAt field in Prisma schema ==="
fd "schema.prisma" | head -5 | xargs grep -n "paidAt\|model Payout" 2>/dev/null || echo "Prisma schema not found in fd results"

echo ""
echo "=== Check export route for commissions ==="
fd "export" --type=f | grep -i commission | head -10

echo ""
echo "=== Check CommissionDetailSchema usage to see paidAt collision ==="
rg -n "CommissionDetailSchema\|CommissionEnrichedSchema" --type=ts -C2

echo ""
echo "=== Check for other callers of getCommissions that may not need payout ==="
rg -n "from.*get-commissions\|require.*get-commissions" --type=ts

Length of output: 17546



@pepeladeira Here's the full review of PR #4048.


Review Summary

No breaking changes. All modifications are purely additive:

  • paidAt is a new nullable field on the API response — existing consumers ignoring extra fields are unaffected
  • The export column has default: false — existing exports won't include it unless explicitly opted in
  • Schema change uses .nullish() — all existing Zod consumers continue to pass validation

File-by-file findings

get-commissions.ts

The payout: { select: { paidAt: true } } include is well-scoped (only fetches one field), but it adds a LEFT JOIN to every call to getCommissions, including the async batch export cron (fetch-commissions-batch.ts). Since all 3 callers are list/export paths that do benefit from paidAt, this is acceptable overhead — just worth knowing.

commissions.ts (schemas)

CommissionEnrichedSchema gets paidAt: z.date().nullish() which is correct. Note that since CommissionDetailSchema extends CommissionEnrichedSchema, it now has paidAt both at the top level (inherited) and nested under payout.paidAt (existing). This is intentional duplication for convenience but worth documenting.

The new COMMISSION_EXPORT_COLUMNS entry has default: false

format-commissions-for-export.ts

Minor inconsistency: the date column type schema uses .nullable() but has no .default(""), unlike the other type schemas:

// number, money, string all have .default(...)
number: z.coerce.number().nullable().default(0)...
money: z.string().nullable().default("")...
string: z.string().nullable().default("")...

// date is missing .default("")
date: z.union([z.date(), z.string()]).nullable().transform(...)

This isn't a runtime bug right now because paidAt is always set to null (never undefined) via ?? null, and .nullable() accepts null. But if a future date column is added and its value arrives as undefined, Zod would throw. Consider adding .default(null) for consistency:

date: z
  .union([z.date(), z.string()])
  .nullable()
  .default(null)
  .transform((date) => {
    if (!date) return "";
    return date instanceof Date ? date.toISOString() : date;
  }),

route.ts

The mapping paidAt: c.payout?.paidAt ?? null is correct and consistent with the export formatter.


OpenAPI/docs impact

CommissionEnrichedSchema is referenced in list-commissions.ts for the OpenAPI spec, so paidAt will automatically appear in the documented response shape. ✅


Summary: Safe to merge. One minor suggestion to add .default(null) on the date column type schema for defensive consistency.

✅ Action performed

Full review finished.

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.

1 participant