Skip to content

Add paid at to commissions API and export#4048

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

Add paid at to commissions API and export#4048
pepeladeira wants to merge 4 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 showing when the related payout was completed (or null when unavailable).
    • The Paid at field is returned by the commissions API and added as a Paid at column in commission exports.
    • Export formatting now supports Date or string values and gracefully handles missing inputs.

@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 Jul 17, 2026 4:54pm

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: cc7000d9-b5d4-404a-8e62-57f2d7eb23e6

📥 Commits

Reviewing files that changed from the base of the PR and between b2fd395 and aafe9ee.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/commissions/route.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/commissions/route.ts

📝 Walkthrough

Walkthrough

Adds payout payment timestamps to commission API responses and exports. The commission schema and export column configuration now define paidAt, while commission retrieval includes the payout timestamp and export formatting normalizes date values.

Changes

Commission paidAt field

Layer / File(s) Summary
Schema and export column config
apps/web/lib/zod/schemas/commissions.ts
CommissionEnrichedSchema gains a nullable paidAt field; 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 includes payout.paidAt; the GET route maps it onto each commission before schema validation.
Export formatter
apps/web/lib/api/commissions/format-commissions-for-export.ts
The date schema accepts Date, strings, and nullish values, normalizing them to ISO strings or empty strings; formatted rows include paidAt.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • dubinc/dub#3922: Extends the same export pipeline files with another column.
  • dubinc/dub#3998: Sets payout.paidAt in the payment flow read by this change.

Suggested reviewers: steven-tey

🚥 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 clearly summarizes the main change: adding paidAt to the commissions API and export.
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.
✨ 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.

@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