feat(collection-map): require ready_notes when marking ready

This commit is contained in:
SJCoetz 2026-07-10 00:04:01 +02:00
parent 4e0d45198b
commit 13165bfb8c

View file

@ -30,6 +30,7 @@ type BodyInput = {
driverId?: string;
date?: string;
ready_for_collection?: boolean;
ready_notes?: string;
};
export async function PATCH(
@ -55,6 +56,20 @@ export async function PATCH(
assignedAt = iso;
}
// `ready_notes` is required (non-empty after trim) when the operator
// is marking a row ready. The Collection Pool modal enforces this
// client-side, but we re-check here so a direct API call can't skip
// it. `ready_notes` is ignored (and not required) on the unmark
// path and on pure driver-assign paths.
const readyNotes = typeof body.ready_notes === "string" ? body.ready_notes.trim() : "";
const isMarkingReady = body.ready_for_collection === true;
if (isMarkingReady && readyNotes.length === 0) {
return NextResponse.json(
{ error: "A note is required when marking ready." },
{ status: 400 },
);
}
const isAssigning = typeof driverId === "string" && driverId.length > 0;
const patch: Record<string, unknown> = normalizeOrderItemStatusInput({
item_status: isAssigning ? "assigned" : "collection_pool",
@ -77,6 +92,10 @@ export async function PATCH(
// default we computed above.
if (typeof body.ready_for_collection === "boolean") {
patch.ready_for_collection = body.ready_for_collection;
if (body.ready_for_collection && readyNotes.length > 0) {
// Trimmed server-side so the audit log is always clean.
patch.notes = readyNotes;
}
}
const pb = await getAdminPocketBase();
@ -94,6 +113,8 @@ export async function PATCH(
drv_status: patch.drv_status,
drv_id: patch.drv_id,
assigned_at: patch.assigned_at,
notes: patch.notes ?? null,
ready_for_collection: patch.ready_for_collection,
},
});
} catch (error) {