// Public REST: rare furni trade values (website_rare_values). // AtomCMS JSON API parity — read-only catalog of rares with their credit / // currency values. Supports ?category= filter; paginated, ordered by name. import { apiJson, pagination } from "@/lib/api"; import { prisma } from "@/lib/prisma"; export const dynamic = "force-dynamic"; export async function GET(req: Request) { const sp = new URL(req.url).searchParams; const { page, perPage, skip, take } = pagination(sp); // Optional ?category= filter (category_id is a BigInt). const categoryRaw = sp.get("category"); let where: { categoryId?: bigint } = {}; if (categoryRaw && /^\d+$/.test(categoryRaw)) { try { where = { categoryId: BigInt(categoryRaw) }; } catch { where = {}; } } try { const [total, data] = await Promise.all([ prisma.websiteRareValues.count({ where }), prisma.websiteRareValues.findMany({ where, orderBy: { name: "asc" }, skip, take, select: { id: true, categoryId: true, itemId: true, name: true, creditValue: true, currencyValue: true, currencyType: true, furnitureIcon: true, }, }), ]); return apiJson({ data, meta: { page, perPage, total, lastPage: Math.max(1, Math.ceil(total / perPage)) }, }); } catch { // DB unreachable — never 500; return an empty, well-formed payload. return apiJson( { data: [], meta: { page, perPage, total: 0, lastPage: 1 } }, { status: 200 }, ); } }