feat(api): geocode member city/region to lat/long on save
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 33
- Forks
- 104
- Avg merge
- 12h 3m
- Merged PRs (30d)
- 10
Description
Summary
profiles already has city, region, countryId, latitude, longitude, and showOnMap columns, but latitude/longitude are never populated automatically — they exist only because someone manually wrote to them. A geocoding pipeline should run on profile address changes so map placement just works.
Requirements
- On
PATCH /me/profile(packages/api/src/routes/me.ts): whencity,region, orcountryIdchanges, enqueue or inline-call a geocoder - On
PATCH /admin/users/:id(packages/api/src/routes/admin/users/byId.ts): same trigger when an admin edits the address fields - Geocoded values write to
profiles.latitude/profiles.longitude; if the geocode fails (no result, rate-limited, network error) the existing lat/long stays put and we log the failure - A nullable
profiles.geocoded_attimestamp records the last successful geocode — distinguishes "never tried" from "tried, no result" - Backfill script
packages/api/scripts/geocode-profiles.tsfor the existing roster: iterate over profiles with city + country and no lat/long - Geocoder choice (Nominatim vs Mapbox) decided in coordination with #1969 — orgs and members should use the same one
Context
profiles.{city, region, countryId, latitude, longitude} already exist (packages/api/src/db/schema/users.ts:103-115). The map plumbing on the web app reads these — populating them is the missing link.
Pairs with #1969 (org-side addresses + geocoding) — same pipeline serves both.
Implementation Notes
Nominatim has a 1 req/sec public rate limit + a User-Agent header requirement; that's plenty for an admin PATCH but means the backfill script needs a setTimeout delay between calls. Mapbox is faster but needs an API key + budget. Decide once for both #1969 and this issue and reuse the same lib/geocode.ts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read packages/api/src/routes/me.ts and packages/api/src/routes/admin/users/byId.ts, then inspect packages/api/src/db/schema/users.ts:103-115. Coordinate the Nominatim or Mapbox choice with #1969 before shaping the shared pipeline. Done means address changes and the backfill script populate coordinates, preserve existing values on failure, log failures, and record successful geocoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100