Implement contact_detail_repository base queries
epic-contact-detail-and-edit-foundation-task-003 — Build the contact-detail-repository with typed Supabase query wrappers for fetching full contact profiles. Implement getContactById returning all non-encrypted fields, and multi-chapter affiliation retrieval joining the contact_chapters table. Enforce RLS so coordinators only access contacts within their organisation scope.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Use PostgREST embedded resource syntax in the .select() call: `contacts(*, contact_chapters(chapter_id, chapter_name, is_primary))` to get contact + chapters in one round-trip. Map the nested JSON array directly to List
Define all Supabase table and column names as static const strings in a SupabaseSchema class to avoid typos that cause silent runtime failures.
Testing Requirements
Unit tests with a mocked Supabase client: (1) getContactById returns ContactDetailRecord with correctly mapped plaintext fields; (2) chapterAffiliations list contains all chapters from the mocked join result; (3) ContactNotFoundException is thrown when Supabase returns an empty list; (4) EncryptedFieldStub objects are present and plaintext fields are absent for encrypted columns. Integration test against a local Supabase instance: verify RLS blocks cross-organisation reads, verify multi-chapter contact returns all affiliations. Test watchContactById emits updated records when the contact row is modified via Realtime.
Blindeforbundet's encryption key retrieval mechanism may not be finalised at implementation time, or session key availability via Supabase RLS may be inconsistent, causing decryption failures that expose masked placeholders to users and degrade the experience.
Mitigation & Contingency
Mitigation: Agree with Blindeforbundet on key storage and retrieval contract before implementation starts. Prototype key retrieval in a spike against the staging Supabase instance and validate the full decrypt/verify cycle with real test data before committing to the implementation.
Contingency: Implement a fallback that shows a 'field temporarily unavailable' state with a retry affordance. Log decryption failures server-side for audit. Escalate to Blindeforbundet stakeholders to unblock key management before the service tier epic begins.
NHF contacts may belong to up to 5 chapters, each governed by separate RLS policies. A coordinator's chapter scope may not cover all affiliations, causing partial profile reads or silent data omissions that are difficult to detect in tests.
Mitigation & Contingency
Mitigation: Map all RLS policy combinations for multi-chapter contacts early. Write integration tests that create contacts with 5 affiliations and query them from coordinators with varying chapter scopes. Use Supabase's RLS test utilities to verify row visibility per role.
Contingency: Add an explicit 'affiliation partially visible' state in the repository response model so the UI can communicate scope limitations to the coordinator rather than silently showing incomplete data.
Organisation-specific validation rules (e.g., NHF chapter limit, Blindeforbundet encrypted field edit flow) may expand in scope during implementation as edge cases are discovered, causing the validator to grow beyond the planned complexity.
Mitigation & Contingency
Mitigation: Define the complete validation rule set with product and org stakeholders before coding begins. Document each rule with its source organisation and acceptance test. Use a rule registry pattern so new rules can be added without modifying core validator logic.
Contingency: Timebox validator enhancements to 2 hours per additional rule. Defer non-blocking rules to a follow-on maintenance task rather than blocking the epic delivery.