Organization Hierarchy Repository
Component Detail
Data Layer
high complexity
backend
1
Dependencies
2
Dependents
0
Entities
0
Integrations
Description
Data access layer for organization hierarchy queries against the organizations and organization_memberships tables. Wraps recursive CTE PostgreSQL queries for tree traversal and provides typed domain objects. All reads are scoped to the admin's organizational ancestry to enforce tenant isolation.
organization-hierarchy-repository
Responsibilities
- Execute recursive CTE queries for upward and downward tree traversal with depth limits
- Persist new organization records with self-referential parent_organization_id
- Fetch subtree nodes with configurable maximum depth
- Return membership counts per organization node for display in the management page
- Delete organizations and cascade-update affected membership records
Interfaces
findSubtree(rootId: string, maxDepth: number): OrganizationNode[]
findAncestors(orgId: string): Organization[]
findDescendants(orgId: string): Organization[]
create(data: CreateOrgDto): Organization
update(orgId: string, data: UpdateOrgDto): Organization
delete(orgId: string): void
getMembershipCount(orgId: string): number
findByParentId(parentId: string): Organization[]
Relationships
Dependents (2)
Components that depend on this component