Add /api/register/all endpoint + fix pb.ts timeout + wire registrations page to it
This commit is contained in:
parent
68ce2bd586
commit
d2a7de5ccc
3 changed files with 42 additions and 1 deletions
40
app/api/register/all/route.ts
Normal file
40
app/api/register/all/route.ts
Normal file
|
|
@ -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<RegItem>("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 });
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ export default function RegistrationsPage() {
|
|||
const [copiedId, setCopiedId] = useState<string | null>(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 || []);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export async function pbFetch<T>(path: string, query: Record<string, string | nu
|
|||
const res = await fetch(url, {
|
||||
headers: { Authorization: TOKEN as string },
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.text();
|
||||
|
|
|
|||
Loading…
Reference in a new issue