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);