All files / libs/tenants/teams/shared/tree/src/lib get-team-descendants.ts

100% Statements 25/25
100% Branches 4/4
100% Functions 5/5
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 14x 14x 14x 14x 19212x 19220x 19220x 19226x 14x 19226x 14x 1x 1x 6x 6x 6x 5640x 6x  
import { type TeamContract, type TeamTreeNode } from '@amalia/tenants/teams/types';
 
function getTeamDescendantsRecursive<
  TTeam extends Pick<TeamContract, 'id' | 'parentTeamId'>,
  TTeamTreeNode extends TeamTreeNode<TTeam>,
>(teamNode: TTeamTreeNode, acc: TTeam[] = []): TTeam[] {
  teamNode.children.forEach((child) => {
    acc.push(child.team);
    getTeamDescendantsRecursive(child, acc);
  });
 
  return acc;
}
 
export function getTeamDescendants<
  TTeam extends Pick<TeamContract, 'id' | 'parentTeamId'>,
  TTeamTreeNode extends TeamTreeNode<TTeam> = TeamTreeNode<TTeam>,
>(teamNode: TTeamTreeNode): TTeam[] {
  return getTeamDescendantsRecursive(teamNode);
}