Hierarchy Service
Component Detail
Service Layer
high complexity
backend
3
Dependencies
2
Dependents
2
Entities
0
Integrations
Description
Backend service responsible for all CRUD operations on the organizational hierarchy. Uses recursive CTEs in PostgreSQL to traverse the tree upward and downward, anchored to the requesting admin's scope for strict data isolation and double-counting prevention in Bufdir reporting.
hierarchy-service
Responsibilities
- Create, update, and delete organization nodes with parent_organization_id references
- Traverse hierarchy upward and downward using recursive CTEs
- Enforce a maximum depth of three levels (national, regional, local)
- Aggregate activity and reporting data across all descendant organizations
- Resolve primary_organization_id for users belonging to multiple organizations
Interfaces
getOrganizationTree(rootOrgId: string, adminScope: OrgScope): OrganizationNode
createChildOrganization(parentId: string, data: CreateOrgDto): Organization
updateOrganization(orgId: string, data: UpdateOrgDto): Organization
deleteOrganization(orgId: string): void
getDescendantIds(orgId: string): string[]
getAncestorIds(orgId: string): string[]
aggregateReportingData(orgId: string, includeDescendants: boolean): AggregatedStats
resolveUserPrimaryOrganization(userId: string): string
Relationships
Dependencies (3)
Components this component depends on
Dependents (2)
Components that depend on this component
Related Data Entities (2)
Data entities managed by this component