Skip to content

fix(api): guard contacts without a usual place of residence on the follow-up dashboard - #19

Merged
lbrunofidelis merged 1 commit into
devfrom
fix/#35-follow-up-dashboard-notification-only-address
Sep 1, 2026
Merged

lbrunofidelis merged 1 commit into
devfrom
fix/#35-follow-up-dashboard-notification-only-address

Conversation

@lbrunofidelis

Copy link
Copy Markdown
Collaborator

Problem

The follow-up dashboard returns a 500 and never loads:

GET /api/outbreaks/{outbreakId}/range-follow-ups
TypeError: Cannot read properties of undefined (reading 'locationId')

Root cause

In FollowUp.getOrCountGroupedByPerson, the record post-processing looks up the contact's usual place of residence with addresses.find(...) and dereferences .locationId on the result, guarded only by addresses.length > 0. When a contact has addresses but none of them is a usual place of residence, find returns undefined and the request blows up. This happens on both passes: while collecting the location ids and while attaching the resolved locations.

Those lines are original Go.Data code and were never touched here. What started triggering them is the notification address type, which lets a contact exist with a notification address and no usual place of residence. Every other place in the codebase that resolves the usual place of residence already handles the missing address; only these two did not.

Fix

Check the lookup result before reading locationId, matching the pattern already used elsewhere in the codebase. Contacts without a usual place of residence are now listed without a resolved location instead of breaking the whole request.

Verification

Reproduced against a local database holding a contact whose only address is a notification address and who owns the outbreak's only follow-up, by calling the method the same way the remote method does.

Before the fix:

RESULT: FAILED
error name: TypeError
error message: Cannot read properties of undefined (reading 'locationId')

After the fix, on the same data plus a seeded contact that does have a usual place of residence:

RESULT: OK
groups returned: 2
  CO-ZZTEST01     | addresses: [USUAL_PLACE_OF_RESIDENCE] | follow-ups: 1 | location resolved: true
  CO-0000000005   | addresses: [NOTIFICATION]             | follow-ups: 1 | location resolved: false

Contacts with a usual place of residence still get their location resolved. npm run lint passes on the changed file.

The follow-up dashboard crashed with a 500 whenever a contact had
addresses but none of them was a usual place of residence, which is
possible for contacts that only carry a notification address.
@lbrunofidelis
lbrunofidelis merged commit 7457d06 into dev Sep 1, 2026
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.

1 participant