WFDASH-WEBAPP/src/app/api/v1/orders/route.ts
SJCoetz 6c07a91693 refactor: drop order-level status, shift to item-driven workflow
This commit overhauls the order management system to use item-level status tracking instead of a single order-level status:
- Remove deprecated `orders.status` field and add `invoiced` and quote match audit fields
- Add `isOrderComplete` utility with tests to validate fully delivered orders
- Add purchase order PDF rendering support and tooling
- Add geo coordinate fields for companies/customers with map link UI
- Add REST management APIs for customers, companies, and suppliers
- Update customer/company services to use relation fields instead of free text
- Add status pill and tab filter components for item status visualization
- Add quote-to-order matching logic and unit tests
- Update all pages, components, and tests to match the new schema
- Include all required PocketBase migrations and schema updates
2026-06-29 13:06:01 +02:00

30 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getAdminPocketBase } from "@/lib/server/pocketbase-admin";
import { assertAgentAuth } from "@/lib/server/agent-auth";
export async function GET(req: NextRequest) {
try {
assertAgentAuth(req);
const pb = await getAdminPocketBase();
const page = Number(req.nextUrl.searchParams.get("page") || "1");
const perPage = Number(req.nextUrl.searchParams.get("perPage") || "50");
const search = req.nextUrl.searchParams.get("search") || "";
// `orders` no longer carries a `status` field — items drive the
// workflow (see src/lib/item-status-ui.ts). Callers that need
// item-status filtering should query `order_items` directly.
const filter = search ? `order_number ~ "${search}"` : "";
const result = await pb.collection("orders").getList(page, perPage, {
filter,
sort: "-created",
expand: "company,customer,quote",
});
return NextResponse.json(result);
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to fetch orders";
const status = (error as Error & { status?: number }).status || 500;
return NextResponse.json({ error: message }, { status });
}
}