diff --git a/src/app/projects/[projectId]/work-orders/[workOrderId]/ids.ts b/src/app/projects/[projectId]/work-orders/[workOrderId]/ids.ts new file mode 100644 index 00000000..470722fd --- /dev/null +++ b/src/app/projects/[projectId]/work-orders/[workOrderId]/ids.ts @@ -0,0 +1,18 @@ +/** + * Path-segment parsing for the work-order detail route (issue #422). + * + * Kept out of `page.tsx` because Next.js rejects any non-default export from a + * page module beyond its handful of allowed fields — a helper exported there + * fails the build. Mirrors `parseProjectId` in `../../../guards`. + */ + +/** + * Parse a `[workOrderId]` path segment into the bigint PK it addresses, or null + * for anything that is not a bare positive integer — so a junk segment becomes + * a 404 rather than a Drizzle error. + */ +export function parseWorkOrderId(workOrderId: string): bigint | null { + if (!/^\d+$/.test(workOrderId)) return null; + const parsed = BigInt(workOrderId); + return parsed > 0n ? parsed : null; +} diff --git a/src/app/projects/[projectId]/work-orders/[workOrderId]/page.test.tsx b/src/app/projects/[projectId]/work-orders/[workOrderId]/page.test.tsx index 5111b09a..54c8d7d9 100644 --- a/src/app/projects/[projectId]/work-orders/[workOrderId]/page.test.tsx +++ b/src/app/projects/[projectId]/work-orders/[workOrderId]/page.test.tsx @@ -39,7 +39,8 @@ vi.mock("next/link", () => ({ }) => {children}, })); -import WorkOrderDetailPage, { parseWorkOrderId } from "./page"; +import WorkOrderDetailPage from "./page"; +import { parseWorkOrderId } from "./ids"; const CLIENT_ORG = "11111111-1111-1111-1111-111111111111"; const CONTRACTOR_ORG = "22222222-2222-2222-2222-222222222222"; diff --git a/src/app/projects/[projectId]/work-orders/[workOrderId]/page.tsx b/src/app/projects/[projectId]/work-orders/[workOrderId]/page.tsx index 6a6641e8..d3dbbecf 100644 --- a/src/app/projects/[projectId]/work-orders/[workOrderId]/page.tsx +++ b/src/app/projects/[projectId]/work-orders/[workOrderId]/page.tsx @@ -15,6 +15,7 @@ import { WorkOrderHeader, } from "./components/WorkOrderDetailPanels"; import { EvidenceUploadSlot, StageUpdateSlot } from "./components/ActionSlots"; +import { parseWorkOrderId } from "./ids"; export const metadata = { title: "Work order | Ara", @@ -93,14 +94,3 @@ export default async function WorkOrderDetailPage(props: { ); } - -/** - * Parse a `[workOrderId]` path segment into the bigint PK it addresses, or null - * for anything that is not a bare positive integer — so a junk segment becomes - * a 404 rather than a Drizzle error. Mirrors `parseProjectId` in the guards. - */ -export function parseWorkOrderId(workOrderId: string): bigint | null { - if (!/^\d+$/.test(workOrderId)) return null; - const parsed = BigInt(workOrderId); - return parsed > 0n ? parsed : null; -}