feat(context): GET /api/v1/order-items/[id]/context route
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
351c1b2b96
commit
7ad7375dd2
1 changed files with 35 additions and 0 deletions
35
src/app/api/v1/order-items/[id]/context/route.ts
Normal file
35
src/app/api/v1/order-items/[id]/context/route.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getOrderItemContext } from "@/lib/server/order-item-context-service";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/**
|
||||
* GET /api/v1/order-items/[id]/context
|
||||
*
|
||||
* Deterministic SKU-based context for an order_item: last quote,
|
||||
* last order, last invoice checked in, stock state, supplier
|
||||
* history, cheapest. Used by the sprint process modal (L1 inline)
|
||||
* and the orders detail page (L2 popover).
|
||||
*
|
||||
* No Bearer required — matches the existing item-history route's
|
||||
* read-only SKU aggregates pattern. Auth happens upstream at the
|
||||
* page level.
|
||||
*/
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
if (!id || typeof id !== "string") {
|
||||
return NextResponse.json({ error: "Missing id" }, { status: 400 });
|
||||
}
|
||||
try {
|
||||
return NextResponse.json(await getOrderItemContext(id));
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ error: err instanceof Error ? err.message : "Lookup failed" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue