feat(GRO-2154): geocoding endpoints + auto-geocode on client mutations #170
Reference in New Issue
Block a user
Delete Branch "feat/gro-2154-geocoding-endpoints-dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
GRO-2154 — Route Optimization: Geocoding Endpoints (Phase 1.3)
Exposes the GRO-2153 geocoding service as API endpoints and hooks auto-geocoding into the existing client mutation flow.
Endpoints
POST /api/clients/:clientId/geocode— geocode a single client's address (manager-only). Maps outcomes to HTTP status:geocoded → 200, providererror → 502,no_address/unresolved → 422, missing client → 404.POST /api/clients/geocode-batch?limit=— batch-geocode un-geocoded clients (geocodedAt IS NULLwith a non-blank address), throttled by the active provider's rate limiter (manager-only). Processes up tolimitper call (default 50, clamped 1..500) and returnsremainingso managers re-run to completion — avoids HTTP timeouts under Nominatim's 1 req/sec policy.Auto-geocode hook
POST /api/clientsandPATCH /api/clients/:idauto-geocode when anaddressis supplied; the response carries a structuredgeocodingfield. Best-effort — a flaky geocoding backend never breaks the mutation.address: "") drops stalelatitude/longitude/geocodedAt.Persistence & failure surfacing
latitude/longitude/geocodedAtto theclientstable (schema from GRO-2152 migration 0041).geocoded | no_address | unresolved | error— with clear, actionable messages so groomers/managers know when an address is ambiguous.Files
src/services/clientGeocoding.ts— provider resolution, single-client geocode+persist, throttled batch.src/routes/clients.ts— two endpoints + create/update auto-geocode.src/index.ts— manager-only route guard registered before the general/clients/*write guard.src/__tests__/clientGeocoding.test.ts— 8 unit tests (all outcomes, batch tally/remaining, limit clamp, provider default).UAT Playbook
UAT_PLAYBOOK.md§4.2 — added TC-API-2.7 … TC-API-2.17 covering single/batch geocode, manager-only RBAC, no-address/unresolved/not-found cases, auto-geocode on create/update, and address-clear coordinate reset.Verification
pnpm run typecheck✓ (+@groombook/dbtypecheck ✓)pnpm run lint✓ (0 errors)pnpm run test✓ (610 passed, incl. 8 new)Closes GRO-2154.
🤖 Generated with Claude Code