feat: miler delivery-leg fixes — consignmentid, auto route sequencing, admin consignment status

Miler app P0 + contract gaps found in the live audit:

- GET /miler/bookings now returns consignmentid + consignmentstatus on every
  row (nullable), so the app can call deliver/skip/start-delivery straight from
  the list. /miler/assignments is the active-only queue, so this is the
  authoritative fix for stops that have moved onto the delivery leg.
- GET /miler/bookings now returns sequencedat per row: non-null means the
  console/optimizer fixed this stop's order and the app follows step exactly;
  null means no route assigned and the app may fall back to nearest-first.
- Route sequencing (internal/routing) now runs automatically after every
  assignment — customer auto-assign, express auto-assign, manual assign, and
  accept — via SequenceMilerStopsAsync (fire-and-forget, no-op below two active
  stops). Previously only hub batch-assign sequenced, so most riders saw step=0.
- GET /admin/bookings now surfaces the live consignmentstatus alongside the
  frozen booking status, so a Converted_To_Consignment booking can still show
  Out_for_Delivery / Delivered instead of a generic "Active".

Two-step hyperlocal flow (Arrived_At_Pickup, Collected_By_Miler, start-delivery)
stays gated behind MILER_COLLECTED_STATE_ENABLED (default off) until the app
ships; consignmentid/status, GET /miler/consignments/:id, stable error codes and
Idempotency-Key handling are unconditional and safe on the current app.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD
This commit is contained in:
Suriyakumarvijayanayagam
2026-08-24 10:34:12 +05:30
parent 531185cf66
commit f6d339a33f
14 changed files with 541 additions and 34 deletions

View File

@@ -140,8 +140,11 @@ func RegisterRoutes(app *fiber.App, cfg *config.Config) {
milerAuth.Post("/bookings/:bookingid/reached", controllers.BookingReachedCustomer)
milerAuth.Post("/bookings/:bookingid/parcel", controllers.BookingParcelConfirm)
milerAuth.Post("/bookings/:bookingid/payment", controllers.BookingPaymentCollect)
milerAuth.Post("/bookings/:bookingid/pickup-complete", controllers.BookingPickupComplete)
// Money and state-conversion mutations are idempotent: a rider retry over a
// bad connection with the same Idempotency-Key replays the first response
// instead of collecting COD twice or minting a second consignment.
milerAuth.Post("/bookings/:bookingid/payment", middlewares.Idempotency(), controllers.BookingPaymentCollect)
milerAuth.Post("/bookings/:bookingid/pickup-complete", middlewares.Idempotency(), controllers.BookingPickupComplete)
milerAuth.Post("/bookings/:bookingid/vehicle-required", controllers.BookingVehicleRequiredEscalate)
milerAuth.Post("/bookings/:bookingid/cancel", controllers.MilerCancelAssignment)
// Pre-pickup skip: defer a not-yet-picked-up booking without releasing it,
@@ -171,8 +174,15 @@ func RegisterRoutes(app *fiber.App, cfg *config.Config) {
// Miler's own bookings
milerAuth.Get("/bookings", controllers.MilerGetMyBookings)
// Consignment current-state read: lets the app know whether a consignment is
// collected / out-for-delivery / delivered without replaying the logs history.
milerAuth.Get("/consignments/:consignmentid", controllers.MilerGetConsignment)
// Delivery confirmation
milerAuth.Post("/consignments/:id/deliver", controllers.MilerDeliverConsignment)
// start-delivery moves a collected hyperlocal parcel to out-for-delivery (and
// issues the receiver OTP); deliver/skip are the terminal/failed outcomes.
milerAuth.Post("/consignments/:id/start-delivery", middlewares.Idempotency(), controllers.MilerStartDelivery)
milerAuth.Post("/consignments/:id/deliver", middlewares.Idempotency(), controllers.MilerDeliverConsignment)
milerAuth.Post("/consignments/:id/skip", controllers.MilerSkipDelivery)
// Earnings