Skip to content

fix: opportunity district resolution used the wrong source for both types - #926

Open
nadavosa wants to merge 1 commit into
developfrom
nadavosa/895-list-district
Open

fix: opportunity district resolution used the wrong source for both types#926
nadavosa wants to merge 1 commit into
developfrom
nadavosa/895-list-district

Conversation

@nadavosa

Copy link
Copy Markdown
Collaborator

Description

getDistrictToOpportunityHandler's addDistrictToOpportunity (used by the opportunity list route, the legacy creation route, and the single-opportunity route) resolved an opportunity's district from two concepts that don't represent its own location:

  • REGULAR/EVENTS used deal.dealDistrict[0], the deal's volunteer-search target district(s), an unrelated concept.
  • ACCOMPANYING used deal.postcode, which mirrors the agent's own postcode (the exact same value the fallback branch right below it already derives independently), never the appointment's own postcode.

The fix

Per the correct rule in the issue:

  • REGULAR/EVENTS: the opportunity's own agent's district, via agent.districtId. That's an already-loaded FK column wherever agent is loaded at all (no new relation needed, confirmed against the list route's existing relations).
  • ACCOMPANYING: the appointment's own postcode, via accompanying.postcode (falling back to accompanying.postcodeId when only the FK is loaded, not the relation).
  • Kept the existing fallback chain (agent's own address postcode) for whichever branch above doesn't resolve.

Related Issues

Closes #895

Changes

  • src/server/utils/data/add-district-to-opp.ts: corrected district source for both opportunity types.
  • src/test/server/utils/data/add-district-to-opp.test.ts: rewrote the unit tests, the old ones asserted the buggy behavior directly (e.g. "assigns district from deal location", "Priority 1: assigns district from deal postcode").

Testing

No Postgres available in my sandbox by default, spun up a throwaway instance (embedded-postgres, self-contained, no root/Docker needed) to run migrations, seed data, and the full suite for real rather than relying on unit tests alone.

  • tsc --noEmit, eslint (changed files): clean.
  • add-district-to-opp.test.ts: 11/11 passing (fully rewritten for the new behavior).
  • Full suite against a real seeded DB: 797/798 passing. The one failure (swagger.test.ts, a 5s timeout on buildServer() startup) is a pre-existing, unrelated flake, confirmed passing on its own with a longer timeout, and already independently reported by another contributor on a different PR.

Checklist

  • WITHIN THE SCOPE OF AN ISSUE; No unnecessary files included
  • Tests added/updated
  • Documentation updated
  • CI passes

…ypes

addDistrictToOpportunity (used by the opportunity list route, the
legacy creation route, and the single-opportunity route) resolved the
district from two concepts that don't represent the opportunity's own
location:

- REGULAR/EVENTS used deal.dealDistrict[0], the deal's volunteer-search
  target district(s) — unrelated to where the opportunity actually is.
- ACCOMPANYING used deal.postcode, which mirrors the agent's own
  postcode (the same value the fallback branch right below it already
  derives), never the appointment's own postcode.

Per product: REGULAR/EVENTS should use the opportunity's own agent's
district (agent.districtId, an already-loaded FK column wherever agent
is loaded — no new relation needed); ACCOMPANYING should use the
appointment's own postcode (accompanying.postcode, falling back to
accompanying.postcodeId when the relation isn't loaded), with the same
agent-based fallback chain as before if that doesn't resolve.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: expose the correct type-aware district on GET /opportunity list (currently missing/wrong)

1 participant