Skip to content

feat: add GET /api/chats/[id]/artist endpoint#374

Merged
sweetmantech merged 8 commits intotestfrom
codex/arpit-chat-artist-endpoint
Mar 31, 2026
Merged

feat: add GET /api/chats/[id]/artist endpoint#374
sweetmantech merged 8 commits intotestfrom
codex/arpit-chat-artist-endpoint

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented Mar 30, 2026

Summary

  • add dedicated GET /api/chats/[id]/artist endpoint for chat-to-artist lookup
  • enforce auth + chat access checks via existing auth/access modules
  • return stable response shape: room_id, artist_id, artist_exists
  • add focused unit tests for validation, auth errors, access checks, and success cases

Validation

  • pnpm test lib/chats/__tests__/getChatArtistHandler.test.ts
  • pnpm exec eslint "app/api/chats/[id]/artist/route.ts" lib/chats/getChatArtistHandler.ts lib/chats/__tests__/getChatArtistHandler.test.ts

Summary by CodeRabbit

  • New Features
    • Added an API endpoint to fetch artist info for a chat room (returns room ID, artist ID, and whether an artist is assigned).
    • Enabled CORS for cross-origin requests to this endpoint.
    • Strengthened access validation so only authorized users can retrieve artist details.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 30, 2026

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

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Mar 31, 2026 3:43am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ff52c156-a6fb-4c30-a1e7-19a6f1eaa5fd

📥 Commits

Reviewing files that changed from the base of the PR and between 8cd900f and f3ef880.

⛔ Files ignored due to path filters (2)
  • lib/chats/__tests__/getChatArtistHandler.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/chats/__tests__/validateChatAccess.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (2)
  • lib/chats/getChatArtistHandler.ts
  • lib/chats/validateChatAccess.ts

📝 Walkthrough

Walkthrough

Adds a new Next.js API route at /api/chats/[id]/artist with CORS preflight and GET handlers, a dedicated handler getChatArtistHandler that validates access and returns artist info, and updates validateChatAccess to return the full room record and accountId alongside roomId.

Changes

Cohort / File(s) Summary
API Route Handler
app/api/chats/[id]/artist/route.ts
Adds OPTIONS() (CORS preflight) and GET(request, { params }) handlers; resolves dynamic id param and delegates to getChatArtistHandler.
Handler Implementation
lib/chats/getChatArtistHandler.ts
Adds getChatArtistHandler(request, id) which calls validateChatAccess, returns early on NextResponse, otherwise responds 200 with { room_id, artist_id, artist_exists } and CORS headers.
Access Validation
lib/chats/validateChatAccess.ts
Expands exported ValidatedChatAccess to include room: Tables<"rooms"> and accountId: string; validateChatAccess now returns { roomId, room, accountId } on success instead of just { roomId }.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

"A route springs up to fetch the artist's name,
CORS waves hello and auth checks stake their claim.
Room data flows back with a tidy little flag—
Artist exists: true — now the frontend can brag! 🎭"

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Solid & Clean Code ❓ Inconclusive Source files referenced in PR could not be accessed in current repository state, preventing reliable SOLID/Clean Code assessment. Checkout the PR branch (codex/arpit-chat-artist-endpoint) or provide actual file contents for review against SOLID principles and Clean Code standards.

✏️ 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 codex/arpit-chat-artist-endpoint

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

@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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 54072ca and 8cd900f.

⛔ Files ignored due to path filters (1)
  • lib/chats/__tests__/getChatArtistHandler.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (2)
  • app/api/chats/[id]/artist/route.ts
  • lib/chats/getChatArtistHandler.ts

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>
@sweetmantech
Copy link
Copy Markdown
Contributor

Smoke test results (post-merge-conflict resolution, commit f3ef880)

Preview URL: https://recoup-api-git-codex-arpit-chat-arti-e958dd-recoupable-ad724970.vercel.app

Test: GET /api/chats/{id}/artist

GET /api/chats/21373dde-96f6-4022-82c2-ecb6be0e482e/artist with x-api-key200

{
    "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.

@sweetmantech sweetmantech merged commit 11ae9f2 into test Mar 31, 2026
3 of 5 checks passed
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.

2 participants