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 <noreply@anthropic.com>

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
SJCoetz 2026-07-31 15:29:43 +02:00
parent f7b5f3677e
commit d3c3e3908d

View file

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