// Public REST: a single rare furni trade value by id (website_rare_values), // together with its parent category. AtomCMS JSON API parity. Returns { error } // (404) when the id is unknown. import { apiJson } from "@/lib/api"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; export async function GET( _req: Request, { params }: { params: Promise<{ id: string }> }, ) { const { id } = await params; // The primary key is a BigInt; reject non-numeric ids up front. if (!/^\d+$/.test(id)) { return apiJson({ error: "Rare value not found" }, { status: 404 }); } let valueId: bigint; try { valueId = BigInt(id); } catch { return apiJson({ error: "Rare value not found" }, { status: 404 }); } try { const value = await prisma.websiteRareValues.findUnique({ where: { id: valueId }, select: { id: true, categoryId: true, itemId: true, name: true, creditValue: true, currencyValue: true, currencyType: true, furnitureIcon: true, createdAt: true, updatedAt: true, }, }); if (!value) { return apiJson({ error: "Rare value not found" }, { status: 404 }); } // No relation is modelled between the value and its category, so resolve the // category in a second guarded query. let category: { id: bigint; name: string; badge: string; priority: number; } | null = null; try { category = await prisma.websiteRareValueCategories.findUnique({ where: { id: value.categoryId }, select: { id: true, name: true, badge: true, priority: true }, }); } catch { category = null; } return apiJson({ data: { ...value, category } }); } catch { // DB unavailable — treat as not found rather than a 500. return apiJson({ error: "Rare value not found" }, { status: 200 }); } }