From 4ab34c8f0f9b4e1f636a26012f2a75863b471c51 Mon Sep 17 00:00:00 2001 From: yyamashita Date: Fri, 15 May 2026 00:22:37 +0900 Subject: Fix build: merge detail/update into existing API routes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parametric resource routes cause a React Router prod build error (commonjs--resolver server-only module conflict). Merged the GET?id= and PATCH logic into the existing api-bands.tsx and api-artists.tsx instead of creating separate :uuid route files. - GET /api/bands?id=UUID → band detail with links/members - PATCH /api/bands → partial update (append_links, append_members) - Same pattern for /api/artists Co-Authored-By: Claude Sonnet 4.6 --- app/routes/api-artist-detail.tsx | 51 ---------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 app/routes/api-artist-detail.tsx (limited to 'app/routes/api-artist-detail.tsx') diff --git a/app/routes/api-artist-detail.tsx b/app/routes/api-artist-detail.tsx deleted file mode 100644 index 8328bca..0000000 --- a/app/routes/api-artist-detail.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; -import { - getArtistById, - getArtistLinks, - getIpAddress, - updateArtist, -} from "~/lib/db.server"; - -export function loader({ params }: LoaderFunctionArgs) { - const artist = getArtistById(params.uuid!); - if (!artist) return Response.json({ error: "Not found" }, { status: 404 }); - const links = getArtistLinks(artist.id); - return Response.json({ ...artist, links }); -} - -export async function action({ request, params }: ActionFunctionArgs) { - if (request.method !== "PATCH") { - return Response.json({ error: "Method not allowed" }, { status: 405 }); - } - - const artist = getArtistById(params.uuid!); - if (!artist) return Response.json({ error: "Not found" }, { status: 404 }); - - let body: Record; - try { - body = await request.json(); - } catch { - return Response.json({ error: "Invalid JSON body" }, { status: 400 }); - } - - const currentLinks = getArtistLinks(artist.id); - const patchLinks = (body.links as { label: string; url: string }[] | undefined) ?? []; - const appendLinks = body.append_links !== false; - - const existingUrls = new Set(currentLinks.map((l) => l.url)); - const newLinks = appendLinks - ? [...currentLinks.map((l) => ({ label: l.label, url: l.url })), ...patchLinks.filter((l) => !existingUrls.has(l.url))] - : patchLinks; - - updateArtist(artist.id, { - slug: (body.slug as string | undefined) ?? artist.slug, - name: (body.name as string | undefined) ?? artist.name, - links: newLinks, - message: (body.message as string | undefined) || "API update", - ip_address: getIpAddress(request), - }); - - return Response.json(getArtistById(artist.id)); -} - -export default function () { return null; } -- cgit v1.2.3