OrgHierarchyRepository
Component Detail
Data Layer
medium complexity
backend
0
Dependencies
0
Dependents
0
Entities
0
Integrations
Description
Data access layer for persisting organizational units, their parent-child edges, and attribution configuration. It uses adjacency-list storage with closure-table queries for efficient ancestor and descendant lookups at any depth. All writes are transactional to maintain referential integrity across the hierarchy.
org-hierarchy-repository
Sources & reasoning
NHF's unique need (lines 107-109) makes hierarchy management a launch requirement because NHF is one of the initial four organizations and their data integrity depends on it. Blueprint assigns MVP target_release to multi-organization-hierarchy, consistent with admin MVP scope including org management. Without it NHF cannot correctly attribute or report activities.
-
docs/source/likeperson.md · line 109Bredest organisasjonsstruktur: 12 landsforeninger, 9 regioner, 1 400 lokallag - aktivitetsfordeling mellom ledd må støttes.
-
docs/source/likeperson.md · line 107Håndtering av medlemmer i flere lokallag (opptil 5): Avklare tilhørighet og hindre dobbeltrapportering.
Responsibilities
- Store and retrieve org units with full parent-child adjacency data
- Maintain closure table for O(1) ancestor and descendant queries at arbitrary depth
- Persist attribution rules and roll-up configuration per organizational level
- Provide transactional batch writes when moving subtrees to prevent partial updates
- Expose aggregate queries used by the reporting roll-up pipeline
Interfaces
findByTenant(tenantId: string): OrgUnit[]
findDescendants(unitId: string): OrgUnit[]
findAncestors(unitId: string): OrgUnit[]
insertUnit(unit: OrgUnit): OrgUnit
moveSubtree(unitId: string, newParentId: string): void
getAttributionRule(unitId: string): AttributionRule
saveAttributionRule(unitId: string, rule: AttributionRule): void