filter for non parent nodes in create plan

This commit is contained in:
Yisroel Baum 2026-03-21 20:01:21 +02:00
parent 844813499a
commit a527c8b01e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -35,7 +35,9 @@ class CreatePlan
} }
$textId = $request->textId; $textId = $request->textId;
$text = $this->textRepo->find($textId); $text = $this->textRepo->find($textId);
$nodesOfText = $this->nodeRepo->findByTextId($textId); $nodesOfText = $this->filterForNonParentNodes(
$this->nodeRepo->findByTextId($textId)
);
$plan = $this->planRepo->create(new CreatePlanDto( $plan = $this->planRepo->create(new CreatePlanDto(
name: $request->name, name: $request->name,
user: $user, user: $user,
@ -51,4 +53,22 @@ class CreatePlan
return $plan; return $plan;
} }
/**
* @param Node[] $nodes
* @return Node[]
*/
private function filterForNonParentNodes(array $nodes): array
{
$result = [];
foreach ($nodes as $node) {
$result[$node->getId()] = $node;
$parentNode = $node->getParentNode();
if ($parentNode !== null) {
unset($result[$parentNode->getId()]);
}
}
return array_values($result);
}
} }