Service Layer high complexity backend
2
Dependencies
2
Dependents
3
Entities
0
Integrations

Description

Core backend service implementing recursive PostgreSQL CTE queries to fetch ancestor and descendant chains in the organization tree. Enforces circular reference prevention at the API layer and provides hierarchy-aware access control scoping.

Feature: Multi-Organization Hierarchy

organization-hierarchy-service

Responsibilities

  • Fetch full ancestor chain for any organization using recursive CTEs
  • Fetch all descendant organizations (subtree) for a given root node
  • Validate parent assignments to prevent circular references
  • Scope coordinator and admin access queries to their assigned hierarchy level
  • Aggregate reporting data upward through the hierarchy tree

Interfaces

getAncestors(orgId: string): Organization[]
getDescendants(orgId: string): Organization[]
createSubOrganization(parentId: string, data: CreateOrgDto): Organization
moveOrganization(orgId: string, newParentId: string): Organization
validateNoCircularRef(orgId: string, newParentId: string): boolean
getHierarchyTree(rootOrgId: string): HierarchyNode
aggregateStatisticsUpward(orgId: string): AggregatedStats
getScopedOrganizations(userId: string, roleContext: string): Organization[]

Relationships

Dependencies (2)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (3)

Data entities managed by this component