From 13165bfb8c522a40baffb75c3bd5e995259192ae Mon Sep 17 00:00:00 2001 From: SJCoetz Date: Fri, 10 Jul 2026 00:04:01 +0200 Subject: [PATCH] feat(collection-map): require ready_notes when marking ready --- .../collection-map/items/[id]/assign/route.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/app/api/v1/collection-map/items/[id]/assign/route.ts b/src/app/api/v1/collection-map/items/[id]/assign/route.ts index c199184..294a592 100644 --- a/src/app/api/v1/collection-map/items/[id]/assign/route.ts +++ b/src/app/api/v1/collection-map/items/[id]/assign/route.ts @@ -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 = 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) {