diff options
| author | yyamashita <yyamashita@mosquit.one> | 2026-05-15 00:22:37 +0900 |
|---|---|---|
| committer | yyamashita <yyamashita@mosquit.one> | 2026-05-15 00:22:37 +0900 |
| commit | 4ab34c8f0f9b4e1f636a26012f2a75863b471c51 (patch) | |
| tree | afae0d4cf96657d5c55a1d576e365f4d6b177c46 /app/routes/api-band-detail.tsx | |
| parent | eb02f582324aa9b57d287a7b5b809974f4954f98 (diff) | |
Fix build: merge detail/update into existing API routes
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 <noreply@anthropic.com>
Diffstat (limited to 'app/routes/api-band-detail.tsx')
| -rw-r--r-- | app/routes/api-band-detail.tsx | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/app/routes/api-band-detail.tsx b/app/routes/api-band-detail.tsx deleted file mode 100644 index 0cad372..0000000 --- a/app/routes/api-band-detail.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router"; -import { - getBandById, - getBandLinks, - getBandMembers, - getIpAddress, - toSlug, - updateBand, - type MemberInput, -} from "~/lib/db.server"; - -export function loader({ params }: LoaderFunctionArgs) { - const band = getBandById(params.uuid!); - if (!band) return Response.json({ error: "Not found" }, { status: 404 }); - const links = getBandLinks(band.id); - const members = getBandMembers(band.id); - return Response.json({ ...band, links, members }); -} - -export async function action({ request, params }: ActionFunctionArgs) { - if (request.method !== "PATCH") { - return Response.json({ error: "Method not allowed" }, { status: 405 }); - } - - const band = getBandById(params.uuid!); - if (!band) return Response.json({ error: "Not found" }, { status: 404 }); - - let body: Record<string, unknown>; - try { - body = await request.json(); - } catch { - return Response.json({ error: "Invalid JSON body" }, { status: 400 }); - } - - const currentLinks = getBandLinks(band.id); - const currentMembers = getBandMembers(band.id); - - const patchLinks = (body.links as { label: string; url: string }[] | undefined) ?? []; - const patchMembers = (body.members as MemberInput[] | undefined) ?? []; - const appendLinks = body.append_links !== false; - const appendMembers = body.append_members !== 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; - - const existingArtistIds = new Set(currentMembers.map((m) => m.artist_id)); - const newMembers: MemberInput[] = appendMembers - ? [ - ...currentMembers.map((m) => ({ artist_id: m.artist_id, role: m.role, since: m.since ?? "", until: m.until ?? "", note: m.note ?? "" })), - ...patchMembers.filter((m) => !existingArtistIds.has(m.artist_id)), - ] - : patchMembers; - - updateBand(band.id, { - slug: (body.slug as string | undefined) ?? band.slug, - name: (body.name as string | undefined) ?? band.name, - area: (body.area as string | undefined) ?? band.area, - description: "description" in body ? (body.description as string | null) : band.description, - status: (body.status as string | undefined) ?? band.status, - links: newLinks, - members: newMembers, - message: (body.message as string | undefined) || "API update", - ip_address: getIpAddress(request), - }); - - return Response.json(getBandById(band.id)); -} - -export default function () { return null; } |
