From d3c3e3908d5d11c75068823d1f0f956f0cd54438 Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Fri, 31 Jul 2026 15:29:43 +0200 Subject: [PATCH] feat(orders): forward company and rep in review-save route Destructure company and rep from the request body and forward them through updateOrderReviewFields' headerPatch. The service layer (Task 1) already accepts and validates these fields; the route now just plumbs them. Co-Authored-By: Claude Co-authored-by: Orca --- .../api/v1/orders/[id]/review-save/route.ts | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app/api/v1/orders/[id]/review-save/route.ts b/src/app/api/v1/orders/[id]/review-save/route.ts index 674fa8d..0687d2b 100644 --- a/src/app/api/v1/orders/[id]/review-save/route.ts +++ b/src/app/api/v1/orders/[id]/review-save/route.ts @@ -92,9 +92,11 @@ export async function POST( return NextResponse.json({ error: "Body must be an object" }, { status: 400 }); } - const { order_number, customer, items, itemsToAdd, itemsToRemove } = body as { + const { order_number, customer, company, rep, items, itemsToAdd, itemsToRemove } = body as { order_number?: string; customer?: string; + company?: string; + rep?: string; items?: Array<{ id: string; quantity?: number | null; @@ -112,14 +114,23 @@ export async function POST( }; try { - // Header patch — order_number + customer are bundled because the - // collision check needs to fire BEFORE any items[] work runs. - // We always go through `updateOrderReviewFields` — even when the - // patch is empty — so the no-op path returns the current row and - // the route doesn't need a second PB import branch. - const headerPatch: { order_number?: string; customer?: string } = {}; + // Header patch — order_number + customer + company + rep are + // bundled because the collision check needs to fire BEFORE any + // items[] work runs. We always go through `updateOrderReviewFields` + // — even when the patch is empty — so the no-op path returns the + // current row and the route doesn't need a second PB import branch. + // `company` and `rep` are cascaded from the selected customer by + // the modal; the route just forwards them through. + const headerPatch: { + order_number?: string; + customer?: string; + company?: string; + rep?: string; + } = {}; if (typeof order_number === "string") headerPatch.order_number = order_number; if (typeof customer === "string") headerPatch.customer = customer; + if (typeof company === "string") headerPatch.company = company; + if (typeof rep === "string") headerPatch.rep = rep; const order = await updateOrderReviewFields(orderId, headerPatch);