Description

Service for creating and managing items that have a hierarchy

Constructors

Methods

  • Update the current item and any parents to recalculate their ancestorIds, ancestorNamePath and depth Algorithm: If new parentId != null: -> Fetch parent items hierarchically until parentId = null is reached - Calculate ancestorIds - Calculate ancestorNamePath - Calculate depth -> Update organization's ancestorIds, ancestorNamePath, depth to match new structure -> Update childrenCount of new parent to + 1 If new parentId == null: -> Update ancestorIds, ancestorNamePath, depth to default If old parentId is not null: -> Update old parent's childrenCount to - 1

    Parameters

    • entityId: string
    • Optional previousParentId: null | string

    Returns Promise<{
        id: string;
    }>

  • Update children to recalculate their ancestorIds, ancestorNamePath and depth Algorithm:

    1. Set childrenIds = [current org's id] depth = current org's depth, knownPaths = { [current org id]: { ancestorIds, ancestorNamePath } }
    2. Set childrenIds = ids of all items whose parentId is in childrenIds
    3. depth++
    4. For all orgs in childrenIds, update their depth, ancestorIds and ancestorNamePath dynamically based on the value of depth and combining knownPath's ancestorIds/ancestorNamePath + the child's id/name
    5. Set knownPaths to contain mapping of childrenIds to their new ancestorIds and ancestorNamePath
    6. If MAX_DEPTH is reached, stop processing

    Parameters

    • entityId: string

    Returns Promise<{
        id: string;
    }>

Properties

db: Db
hierarchyRespository: MongoRepository<HierarchyEntity>
maxChildren: number
maxDepth: number
COLLECTION_ORGANIZATION: "organizations" = 'organizations'

Generated using TypeDoc