Skip to content

Promote test → main: artist update endpoints (#431) - #454

Merged
sweetmantech merged 13 commits into
mainfrom
test
Apr 17, 2026
Merged

Promote test → main: artist update endpoints (#431)#454
sweetmantech merged 13 commits into
mainfrom
test

Conversation

@sweetmantech

@sweetmantechsweetmantech commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Promotes PR #431 (migrate artist manual update to PATCH /api/artists/{id}) from test to main.

Verified on preview:

🤖 Generated with Claude Code


Summary by cubic

Adds PATCH /api/artists/{id} to update artist name, profile fields, socials, and per-account pinned state in a single request. Returns the caller’s current pin state so name-only updates don’t clobber UI state.

  • New Features

    • New PATCH endpoint accepts name, image, instruction, label, knowledges, profileUrls, and pinned; validates with Zod and responds with the updated artist plus the caller’s pinned.
    • Upserts account_info via upsertArtistInfoFields: preserves omitted fields, de-duplicates knowledges by URL, treats empty label as null; moves knowledgeSchema to lib/artist/knowledge.
    • Adds setAccountArtistPin to persist pin state and includes it in the response; updates socials when profileUrls are provided.
  • Bug Fixes

    • Replaces failing Supabase upsert for pins with select+update/insert to avoid 500s when no unique constraint exists.
    • Prevents returning pinned: false on name-only updates by attaching the requester’s pin state to the response.

Written for commit 7d36cb9. Summary will update on new commits.

Summary by CodeRabbit

Release Notes

  • New Features
    • Artist profiles can now be updated with changes to name, image, description, label, knowledge resources, and social links.
    • Added support for pinning and unpinning artists to your account.

arpitgupta1214and others added 13 commits April 14, 2026 01:29
- Add optional `pinned` boolean to the PATCH body schema so a single request
can update profile fields and pin status together (replaces the separate
POST/DELETE /api/artists/{id}/pin surface on PR #424).
- Upsert the caller's account_artist_ids row via a new single-call
setAccountArtistPin helper, mirroring chat/toggleArtistPin.
- Attach the requester's pinned state onto the response from
selectAccountWithArtistDetails so a name-only PATCH no longer reports
pinned: false and clobbers UI state.
- Extend selectAccountArtistId to return pinned alongside artist_id.
- Tests: pinned-only body, pinned true/false upsert calls, regression guard
that a name-only update on a pinned artist returns pinned: true, and
setAccountArtistPin supabase call shape.
…date/insert
account_artist_ids has no composite unique constraint on (account_id,
artist_id), so supabase upsert with onConflict fails with "no unique or
exclusion constraint matching the ON CONFLICT specification" at runtime.
E2E testing against the PR preview caught this 500 on pin/unpin PATCH
requests.
Look up the existing row first, then update by primary key or insert a
fresh row when the caller has org-only access and no row exists yet.
This matches the pattern the earlier dedicated pin PR (#424) used for
the same reason.
Tests updated to cover the select/update/insert branches and each error
path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
selectAccountWithArtistDetails was doing two operations (fetch account
+ fetch requester's pin row). Move the pin chaining to the caller so
the selector has a single responsibility, and fetch both rows in
parallel from the handler.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ypes
Drop the manual AccountWithArtistDetails type alias and the
`as AccountWithArtistDetails` cast. The supabase client already infers
the join shape; matching the minimal style of selectAccountArtistId.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
updateArtistHandler:
- Extract account_info insert/update branch into upsertArtistInfoFields
(with its own tests). Handler now orchestrates instead of doing the
upsert inline.
setAccountArtistPin:
- Move chained-supabase orchestration out of lib/supabase/account_artist_ids/
into lib/artists/setAccountArtistPin.ts. The supabase dir now holds only
single-query primitives.
- Add updateAccountArtistPinById primitive (single UPDATE).
- Extend insertAccountArtistId to accept optional pinned column.
- selectAccountArtistId now returns id (needed for the update primitive).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Drop unused insertAccountInfo/updateAccountInfo imports in updateArtistHandler test
- Apply prettier/eslint --fix across affected files
- Merge origin/test to bring branch up to date
feat: migrate artist manual update to PATCH /api/artists/{id}
@vercel

vercelBot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

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

ProjectDeploymentActionsUpdated (UTC)
recoup-apiReadyReadyPreviewApr 17, 2026 7:48pm

Request Review

@coderabbitai

coderabbitaiBot commented Apr 17, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR implements a PATCH /api/artists/{id} endpoint to update artist details. It adds request validation, a handler that conditionally updates account-level fields and upserts artist profile info, manages artist-account pinning relationships, and consolidates the Knowledge type definition into a dedicated module for consistency across multiple validation schemas.

Changes

Cohort / File(s)Summary
Route handler
app/api/artists/[id]/route.ts
Adds new exported PATCH function that delegates to updateArtistHandler, following the same pattern as the existing DELETE route.
Request validation
lib/artists/validateUpdateArtistRequest.ts
New module defining updateArtistBodySchema with optional fields (name, image, instruction, label, knowledges, profileUrls, pinned), a refinement requiring at least one field, and validation logic that checks auth, artist existence, and account authorization before returning validated payload.
Update handler
lib/artists/updateArtistHandler.ts
Core PATCH handler orchestrating conditional updates to account fields, artist profile info, socials, and account-artist pinning; fetches updated details and returns 200 response or appropriate error (404/500) with CORS headers.
Artist info operations
lib/artists/upsertArtistInfoFields.ts
New module providing upsertArtistInfoFields that inserts or updates artist profile fields (image, instruction, label, knowledges) with deduplication by URL and null-mapping logic for empty labels.
Account-artist pinning
lib/artists/setAccountArtistPin.ts
New module implementing setAccountArtistPin that updates pinned status if account-artist linkage exists, otherwise creates new linkage with pinned flag.
Knowledge schema consolidation
lib/artist/knowledge.ts, lib/artist/updateArtistProfile.ts, lib/artist/createKnowledgeBase.ts, lib/accounts/validateUpdateAccountRequest.ts
Extracts Knowledge type and knowledgeSchema (with URL validation) into dedicated lib/artist/knowledge.ts; updates imports in dependent files to reference the centralized definition.
Database operations
lib/supabase/account_artist_ids/insertAccountArtistId.ts, lib/supabase/account_artist_ids/selectAccountArtistId.ts, lib/supabase/account_artist_ids/updateAccountArtistPinById.ts, lib/supabase/accounts/selectAccountWithArtistDetails.ts
New and updated query functions: insertAccountArtistId accepts optional pinned flag; selectAccountArtistId now retrieves id, artist_id, and pinned; new updateAccountArtistPinById updates pinned status; new selectAccountWithArtistDetails fetches account with nested artist info and socials.

Sequence Diagram

sequenceDiagram
participant Client
participant Route as API Route<br/>PATCH /artists/{id}
participant Validator as validateUpdateArtistRequest
participant Handler as updateArtistHandler
participant DB as Database<br/>(Supabase)
participant Cache as Response
Client->>Route: PATCH /artists/{id}
Route->>Handler: updateArtistHandler(request, params)
Handler->>Validator: validateUpdateArtistRequest(request, id)
Validator->>DB: validateAccountParams()
Validator->>DB: selectAccounts(id)
Validator->>DB: checkAccountArtistAccess()
alt Validation fails
Validator-->>Handler: NextResponse (400/403/404)
Handler-->>Route: error response
Route-->>Client: error JSON
else Validation succeeds
Validator-->>Handler: ValidatedUpdateArtistRequest
Handler->>DB: updateAccountInfo() / insertAccountInfo()
Handler->>DB: upsertArtistInfoFields()
Handler->>DB: updateAccountSocials() (if profileUrls)
Handler->>DB: setAccountArtistPin() (if pinned provided)
Handler->>DB: selectAccountWithArtistDetails(artistId)
Handler->>DB: selectAccountArtistId(accountId, artistId)
DB-->>Handler: artist details + pin status
Handler-->>Route: 200 response with artist JSON
Route-->>Client: formatted artist data
end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🎨 A patch to paint the artist's way,
With knowledge schemas on display,
Updates flow from client to DB,
Pinned with care, now artists see,
The PATCH that lets them freely say! 📌✨

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check nameStatusExplanationResolution
Solid & Clean Code⚠️ WarningPR violates DRY, SRP, and type safety principles: manual error response constructions instead of utility, unconditional side effects without guards, missing return type annotations, and coupled validation logic.Replace manual error responses with errorResponse() utility, add guard clause for upsertArtistInfoFields, annotate selectAccountArtistId return type, and extract validation sequence into helper.

✏️ 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 test

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.

@sweetmantech
sweetmantech merged commit 6effc53 into mainApr 17, 2026
6 of 7 checks passed
Sign up for freeto 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

@sweetmantech@arpitgupta1214