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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Sep 30, 2025

Summary by CodeRabbit

  • New Features
    • Added an optional tenantId filter for commissions so you can filter by a partner's tenant ID.
    • If tenantId is supplied without partnerId, the system resolves the matching partner for the specified program and returns related commissions.
    • partnerId filter now takes precedence when both partnerId and tenantId are provided.
    • Backwards-compatible when tenantId is not used.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Walkthrough

Adds an optional tenantId query to the commissions schema and updates the commissions API route to resolve partnerId from programEnrollment when tenantId is provided and partnerId is not; throws a DubApiError.not_found if no partner is found.

Changes

Cohort / File(s) Summary of edits
API route filtering & runtime resolution
apps/web/app/(ee)/api/commissions/route.ts
Extracts tenantId from parsed query; changes partnerId to let; if tenantId is present and partnerId is absent, queries programEnrollment to resolve partnerId by tenantId and programId; throws DubApiError.not_found when no partner matches; imports DubApiError.
Schema extension
apps/web/lib/zod/schemas/commissions.ts
Adds optional tenantId: z.string().optional() to getCommissionsQuerySchema and updates partnerId description to state that partnerId precedence overrides tenantId.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant C as Client
    participant R as Commissions Route
    participant Z as Zod Schema
    participant E as ProgramEnrollment (Prisma)
    participant P as Prisma (Commissions)
    participant DB as Database

    C->>R: GET /api/commissions?...&tenantId=...&partnerId=...
    R->>Z: parse(getCommissionsQuerySchema)
    Z-->>R: { programId, tenantId?, partnerId?, ... }

    alt partnerId provided
        Note over R: Use provided partnerId (highest precedence)
        R->>P: findMany(where: { partnerId, programId, ... })
    else tenantId provided and no partnerId
        Note over R: Resolve partnerId via programEnrollment
        R->>E: findFirst(where: { tenantId, programId })
        alt enrollment found
            E-->>R: { partnerId }
            R->>P: findMany(where: { partnerId, programId, ... })
        else none found
            E-->>R: null
            R-->>C: 404 DubApiError.not_found
        end
    else neither provided
        R->>P: findMany(where: { programId, ... })
    end

    P->>DB: Execute query
    DB-->>P: Results
    P-->>R: Commissions[]
    R-->>C: 200 OK JSON
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I twitch my whiskers at filters anew,
A tenantId trail the queries pursue.
If partner’s unknown, enrollments will guide,
Through Prisma burrows we swiftly glide.
Carrots aligned, results in a row — hop, code, go! 🥕🐇

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 clearly states the addition of the tenantId filter to the GET /commissions endpoint, which directly reflects the main change implemented in the schema and route handling.
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 update-get-commissions

📜 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 bf5641f and 1b1193e.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/api/commissions/route.ts (3 hunks)
  • apps/web/lib/zod/schemas/commissions.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/commissions/route.ts
🔇 Additional comments (2)
apps/web/lib/zod/schemas/commissions.ts (2)

66-68: LGTM! Clear precedence documentation.

The updated description clearly documents that partnerId takes precedence over tenantId when both are provided, which aligns with the API route implementation.


69-74: Approve — tenantId edge cases handled

  • Unmatched tenantId throws a 404 (DubApiError “not_found”).
  • partnerId overrides tenantId when both are provided.
  • Omitting both preserves existing behavior.

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.

@vercel
Copy link
Contributor

vercel bot commented Sep 30, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 30, 2025 5:50pm

@steven-tey steven-tey merged commit 703ddee into main Sep 30, 2025
8 checks passed
@steven-tey steven-tey deleted the update-get-commissions branch September 30, 2025 17:57
@coderabbitai coderabbitai bot mentioned this pull request Oct 27, 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.

3 participants