feat: add GET /api/chats/[id]/artist endpoint#374
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a new Next.js API route at Changes
Sequence DiagramsequenceDiagram
participant Client
participant Route as GET /api/chats/[id]/artist
participant Handler as getChatArtistHandler
participant Validator as validateChatAccess
participant DB as Database
Client->>Route: GET /api/chats/{id}/artist
Route->>Handler: invoke(request, id)
Handler->>Validator: validateChatAccess(request, id)
alt Validator returns NextResponse (error)
Validator-->>Handler: NextResponse (401/403/404/etc.)
Handler-->>Route: return error response
else Validator returns {roomId, room, accountId}
Handler->>DB: (uses returned room) — no further DB call required or uses room data
Handler-->>Route: 200 JSON { room_id, artist_id, artist_exists } + CORS headers
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/chats/getChatArtistHandler.ts (1)
22-84: Extract a small JSON-with-CORS helper.The same
NextResponse.json(..., { status, headers: getCorsHeaders() })shape is repeated in every branch, and this function is already past the repo’s 50-line target. Pulling that into a tiny helper would remove duplication and keep future response changes in one place.As per coding guidelines,
lib/**/*.ts: "Keep functions under 50 lines" and "DRY: Consolidate similar logic into shared utilities".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/chats/getChatArtistHandler.ts` around lines 22 - 84, Create a small helper (e.g., jsonWithCors or respondJson) that wraps NextResponse.json(payload, { status, headers: getCorsHeaders() }) and return that instead of calling NextResponse.json directly in getChatArtistHandler; replace every return that currently calls NextResponse.json(...) (including the invalid ID, auth/room not found, missing account_id, access denied, and success branches) with calls to the new helper so all responses use the single shared implementation and reduce duplication while keeping getCorsHeaders usage intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/chats/getChatArtistHandler.ts`:
- Around line 19-31: Change the getChatArtistHandler signature to accept a
NextRequest instead of Request so it matches validateAuthContext's expected
input; update the function parameter type in getChatArtistHandler and add the
necessary NextRequest import if missing, then run TypeScript checks to ensure
validateAuthContext(request) and any downstream usages of request still
type-check correctly.
---
Nitpick comments:
In `@lib/chats/getChatArtistHandler.ts`:
- Around line 22-84: Create a small helper (e.g., jsonWithCors or respondJson)
that wraps NextResponse.json(payload, { status, headers: getCorsHeaders() }) and
return that instead of calling NextResponse.json directly in
getChatArtistHandler; replace every return that currently calls
NextResponse.json(...) (including the invalid ID, auth/room not found, missing
account_id, access denied, and success branches) with calls to the new helper so
all responses use the single shared implementation and reduce duplication while
keeping getCorsHeaders usage intact.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a8a45bcb-ad0f-402e-8b4a-81133c3d82fc
⛔ Files ignored due to path filters (1)
lib/chats/__tests__/getChatArtistHandler.test.tsis excluded by!**/*.test.*,!**/__tests__/**and included bylib/**
📒 Files selected for processing (2)
app/api/chats/[id]/artist/route.tslib/chats/getChatArtistHandler.ts
c6036c3 to
c59b00b
Compare
Merge both versions: keep auth fixes (null params, null account_id) from test branch while also returning room + accountId needed by the getChatArtistHandler. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Smoke test results (post-merge-conflict resolution, commit f3ef880)Preview URL: Test: GET /api/chats/{id}/artist
{
"status": "success",
"room_id": "21373dde-96f6-4022-82c2-ecb6be0e482e",
"artist_id": "9105f630-8e9f-4908-a2c4-3f68a6454c78",
"artist_exists": true
}Endpoint working correctly on the preview deployment. |
Summary
GET /api/chats/[id]/artistendpoint for chat-to-artist lookuproom_id,artist_id,artist_existsValidation
pnpm test lib/chats/__tests__/getChatArtistHandler.test.tspnpm exec eslint "app/api/chats/[id]/artist/route.ts" lib/chats/getChatArtistHandler.ts lib/chats/__tests__/getChatArtistHandler.test.tsSummary by CodeRabbit