From d2a7de5ccc6c13fb51280870748810b03f0cccab Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Thu, 30 Jul 2026 20:46:42 +0200 Subject: [PATCH] Add /api/register/all endpoint + fix pb.ts timeout + wire registrations page to it --- app/api/register/all/route.ts | 40 +++++++++++++++++++++++++++++++++++ app/registrations/page.tsx | 2 +- lib/pb.ts | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/api/register/all/route.ts diff --git a/app/api/register/all/route.ts b/app/api/register/all/route.ts new file mode 100644 index 0000000..145e304 --- /dev/null +++ b/app/api/register/all/route.ts @@ -0,0 +1,40 @@ +// app/api/register/all/route.ts +// GET /api/register/all — returns all company registrations, sorted newest first. +// No query filtering — used by the Registrations list page. + +import { NextRequest, NextResponse } from "next/server"; +import { fetchCollection } from "@/lib/pb"; +import type { PBRecord } from "@/lib/pb"; + +export const dynamic = "force-dynamic"; + +interface RegItem extends PBRecord { + id: string; + reference_name: string; + status: string; + proposed_name_1: string; + trading_address: string; + created: string; +} + +export async function GET(req: NextRequest) { + try { + const { searchParams } = new URL(req.url); + const perPage = Math.min(Number(searchParams.get("perPage")) || 500, 500); + + const data = await fetchCollection("ysterbaard_company_registrations", { + page: 1, + perPage, + sort: "-created", + fields: "id,reference_name,status,proposed_name_1,trading_address,created", + }); + + // Sort newest first (nanoid is time-sortable) + const items = data.items.sort((a, b) => b.id.localeCompare(a.id)); + + return NextResponse.json({ items }); + } catch (err) { + console.error("[register/all]", err); + return NextResponse.json({ items: [] }, { status: 200 }); + } +} diff --git a/app/registrations/page.tsx b/app/registrations/page.tsx index 09ac836..39b7a99 100644 --- a/app/registrations/page.tsx +++ b/app/registrations/page.tsx @@ -46,7 +46,7 @@ export default function RegistrationsPage() { const [copiedId, setCopiedId] = useState(null); useEffect(() => { - fetch("/api/register/search?q=&fields=id,reference_name,status,proposed_name_1,trading_address,created&sort=-created") + fetch("/api/register/all?perPage=500") .then((r) => r.json()) .then((d) => { setItems(d.items || []); diff --git a/lib/pb.ts b/lib/pb.ts index 4e8ff2f..7d4aa24 100644 --- a/lib/pb.ts +++ b/lib/pb.ts @@ -25,6 +25,7 @@ export async function pbFetch(path: string, query: Record