Skip to content

Add GET /api/partners/applications#3800

Open
devkiran wants to merge 3 commits intomainfrom
api-list-partner-applications
Open

Add GET /api/partners/applications#3800
devkiran wants to merge 3 commits intomainfrom
api-list-partner-applications

Conversation

@devkiran
Copy link
Copy Markdown
Collaborator

@devkiran devkiran commented Apr 22, 2026

Summary by CodeRabbit

  • New Features

    • Added an API endpoint to list pending partner applications with pagination for your workspace program.
    • OpenAPI spec updated to include the new partner applications operation.
  • Documentation / Validation

    • Added query validation for partner application listing (pagination limits).
    • Renamed/exported partner application response schema and adjusted enum validation for program application rejection reasons.

- Implemented GET /api/partners/applications to retrieve all pending applications for the authenticated workspace's default program.
- Added OpenAPI specification for the new endpoint.
- Updated Zod schemas to support pagination and application data formatting.
- Included necessary imports and utility functions for data handling.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 22, 2026

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Apr 23, 2026 4:37am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4209dbfd-395f-49e4-abdd-011559135fbb

📥 Commits

Reviewing files that changed from the base of the PR and between ccc0c2c and f72093d.

📒 Files selected for processing (1)
  • apps/web/lib/openapi/partners/list-partner-applications.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/lib/openapi/partners/list-partner-applications.ts

📝 Walkthrough

Walkthrough

Adds a workspace-scoped, plan-restricted GET endpoint to list pending partner applications with pagination; registers OpenAPI operation and response schema; updates Zod schemas and enum validation.

Changes

Cohort / File(s) Summary
API Route
apps/web/app/(ee)/api/partners/applications/route.ts
New GET /api/partners/applications route wrapped with withWorkspace and plan enforcement. Parses pagination, resolves default program, queries prisma.programEnrollment for pending enrollments with non-null application, includes partner.platforms, paginates, formats application/partner data, validates against partnerApplicationSchema, returns JSON.
OpenAPI
apps/web/lib/openapi/partners/index.ts, apps/web/lib/openapi/partners/list-partner-applications.ts
Added listPartnerApplications operation and registered GET /partners/applications path; uses getPartnerApplicationsQuerySchema for params and partnerApplicationSchema for 200 response; token security and Partner Applications tag.
Zod Schemas
apps/web/lib/zod/schemas/program-application.ts, apps/web/lib/zod/schemas/programs.ts
Introduced partnerApplicationSchema and getPartnerApplicationsQuerySchema (pagination with PARTNERS_MAX_PAGE_SIZE); aliased partnerApplicationWebhookSchema; changed ProgramEnrollmentApplicationSchema.rejectionReason from z.nativeEnum(...) to z.enum(...).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant API as "Next.js API\n(route.ts)" rect rgba(100,149,237,0.5)
  participant Workspace as "withWorkspace\n(auth/plan)" rect rgba(34,139,34,0.5)
  participant Prisma as "Prisma DB" rect rgba(255,165,0,0.5)
  participant Formatter as "Formatter\n(format/validate)" rect rgba(147,112,219,0.5)

  Client->>API: GET /api/partners/applications?page=&pageSize=
  API->>Workspace: validate workspace and plan, get programId
  Workspace-->>API: workspace + programId
  API->>Prisma: query programEnrollment (status: pending, application != null), include partner.platforms, pagination
  Prisma-->>API: enrollments with application and partner
  API->>Formatter: transform application fields, polyfill partner.platforms, attach status/groupId
  Formatter-->>API: validated array (partnerApplicationSchema)
  API-->>Client: 200 JSON response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • steven-tey
  • pepeladeira

Poem

🐰 I hopped through routes and schemas tonight,
Pending apps in order, shining bright,
Pages turn, partners line the trail,
Formats tidy, no detail frail,
A rabbit cheers — code finished just right! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the primary change: adding a new GET endpoint for /api/partners/applications, which is the main focus of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 api-list-partner-applications

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.

Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (1)
apps/web/lib/zod/schemas/program-application.ts (1)

50-54: Simplify by constructing the object directly from the pagination shape.

getPaginationQuerySchema already returns a shape record, so the empty-object-plus-extend is redundant. This also avoids the extra ZodObject.extend wrapping:

♻️ Proposed refactor
-export const getPartnerApplicationsQuerySchema = z.object({}).extend(
-  getPaginationQuerySchema({
-    pageSize: PARTNERS_MAX_PAGE_SIZE,
-  }),
-);
+export const getPartnerApplicationsQuerySchema = z.object(
+  getPaginationQuerySchema({ pageSize: PARTNERS_MAX_PAGE_SIZE }),
+);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/lib/zod/schemas/program-application.ts` around lines 50 - 54,
Replace the redundant z.object({}).extend(...) pattern by building the schema
directly from the pagination shape: call getPaginationQuerySchema({ pageSize:
PARTNERS_MAX_PAGE_SIZE }) and pass its returned shape into z.object to create
getPartnerApplicationsQuerySchema (referencing
getPartnerApplicationsQuerySchema, getPaginationQuerySchema, and
PARTNERS_MAX_PAGE_SIZE).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/app/`(ee)/api/partners/applications/route.ts:
- Line 59: The createdAt field for partner applications is taken from
programEnrollment (createdAt: programEnrollment.createdAt) which differs from
the webhook convention (application.createdAt) and causes inconsistent ordering;
update the listing code in route.ts to use application.createdAt for the
createdAt property and change the query/orderBy to order by
application.createdAt descending so it matches partnerApplicationWebhookSchema /
partnerApplicationSchema and the webhook handler
(apps/web/lib/partners/complete-program-applications.ts).
- Around line 44-71: The mapped "result" can contain nulls due to the `if
(!application) return null` branch inside `applications.map(...)`, which will
make `z.array(partnerApplicationSchema).parse(result)` throw; to fix, either
remove the unreachable null-return branch in the `applications.map` callback
(remove the `if (!application) ...` and assume `application` exists) or ensure
you filter out nulls before parsing (e.g., filter the `result` from
`applications.map` to remove null/undefined entries) so that the value passed to
`NextResponse.json(z.array(partnerApplicationSchema).parse(...))` contains only
valid partner application objects; update code paths that reference
`applications.map`, `formatApplicationFormData`, `polyfillSocialMediaFields`,
and the final `NextResponse.json(...)` call accordingly.

---

Nitpick comments:
In `@apps/web/lib/zod/schemas/program-application.ts`:
- Around line 50-54: Replace the redundant z.object({}).extend(...) pattern by
building the schema directly from the pagination shape: call
getPaginationQuerySchema({ pageSize: PARTNERS_MAX_PAGE_SIZE }) and pass its
returned shape into z.object to create getPartnerApplicationsQuerySchema
(referencing getPartnerApplicationsQuerySchema, getPaginationQuerySchema, and
PARTNERS_MAX_PAGE_SIZE).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 30c443e6-d320-40ee-8aee-7f878d600245

📥 Commits

Reviewing files that changed from the base of the PR and between d0e39df and 4ff9461.

📒 Files selected for processing (5)
  • apps/web/app/(ee)/api/partners/applications/route.ts
  • apps/web/lib/openapi/partners/index.ts
  • apps/web/lib/openapi/partners/list-partner-applications.ts
  • apps/web/lib/zod/schemas/program-application.ts
  • apps/web/lib/zod/schemas/programs.ts

Comment thread apps/web/app/(ee)/api/partners/applications/route.ts
Comment thread apps/web/app/(ee)/api/partners/applications/route.ts Outdated
@devkiran devkiran requested a review from steven-tey April 22, 2026 10:03
Copy link
Copy Markdown
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: 1

♻️ Duplicate comments (1)
apps/web/app/(ee)/api/partners/applications/route.ts (1)

37-38: ⚠️ Potential issue | 🟡 Minor

Order by the same timestamp returned to clients.

The response now exposes application.createdAt, but pagination still sorts by programEnrollment.createdAt. If those timestamps diverge, pages are not ordered by the visible application submission time. Consider ordering by the application’s createdAt as well.

Suggested direction
       orderBy: {
-        createdAt: "desc",
+        application: {
+          createdAt: "desc",
+        },
       },
#!/bin/bash
# Verify the route still sorts by enrollment.createdAt while returning application.createdAt.

rg -n -C4 'orderBy:|createdAt: application' \
  'apps/web/app/(ee)/api/partners/applications/route.ts'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/app/`(ee)/api/partners/applications/route.ts around lines 37 - 38,
The pagination sort uses programEnrollment.createdAt but the response exposes
application.createdAt, so update the query in route handler to order by the
application's createdAt instead of programEnrollment.createdAt (or add a
secondary orderBy on application.createdAt) so that the returned list is ordered
by the same timestamp shown to clients; locate the query referencing orderBy and
programEnrollment.createdAt in
apps/web/app/(ee)/api/partners/applications/route.ts (the block constructing the
DB query and the orderBy clause) and replace or augment it to use
application.createdAt as the primary sort key.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/app/`(ee)/api/partners/applications/route.ts:
- Around line 16-41: The pagination schema lets non-integer numbers through,
causing Prisma take/skip to receive floats; update the Zod schema that defines
page and pageSize (the getPaginationQuerySchema used by
getPartnerApplicationsQuerySchema) to add .int() to both page and pageSize so
only integer values pass validation before hitting
prisma.programEnrollment.findMany (which uses take and skip).

---

Duplicate comments:
In `@apps/web/app/`(ee)/api/partners/applications/route.ts:
- Around line 37-38: The pagination sort uses programEnrollment.createdAt but
the response exposes application.createdAt, so update the query in route handler
to order by the application's createdAt instead of programEnrollment.createdAt
(or add a secondary orderBy on application.createdAt) so that the returned list
is ordered by the same timestamp shown to clients; locate the query referencing
orderBy and programEnrollment.createdAt in
apps/web/app/(ee)/api/partners/applications/route.ts (the block constructing the
DB query and the orderBy clause) and replace or augment it to use
application.createdAt as the primary sort key.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9978d6f-7de5-4765-9645-f7cc9bec78c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4ff9461 and ccc0c2c.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/partners/applications/route.ts

Comment thread apps/web/app/(ee)/api/partners/applications/route.ts
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