From a527c8b01e38a5acc8b905c60ffa553c7a705b3d Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 21 Mar 2026 20:01:21 +0200 Subject: [PATCH] filter for non parent nodes in create plan --- app/Plan/UseCases/CreatePlan.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/Plan/UseCases/CreatePlan.php b/app/Plan/UseCases/CreatePlan.php index 2ce21c4..cf9a3d2 100644 --- a/app/Plan/UseCases/CreatePlan.php +++ b/app/Plan/UseCases/CreatePlan.php @@ -35,7 +35,9 @@ class CreatePlan } $textId = $request->textId; $text = $this->textRepo->find($textId); - $nodesOfText = $this->nodeRepo->findByTextId($textId); + $nodesOfText = $this->filterForNonParentNodes( + $this->nodeRepo->findByTextId($textId) + ); $plan = $this->planRepo->create(new CreatePlanDto( name: $request->name, user: $user, @@ -51,4 +53,22 @@ class CreatePlan 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); + } }