textId === null) { throw new BadRequestException('textId is required'); } if ($request->parentNodeId === null) { throw new BadRequestException('parentNodeId is required'); } if ($request->titlePrefix === null) { throw new BadRequestException('titlePrefix is required'); } if ($request->count === null) { throw new BadRequestException('count is required'); } if ($request->count < 1) { throw new BadRequestException('count must be at least 1'); } $text = $this->textRepo->find($request->textId); if ($text === null) { throw new DomainException("Text with id: {$request->textId} doesnt exist"); } $parentNode = $this->nodeRepo->find($request->parentNodeId); if ($parentNode === null) { throw new DomainException("Node with id: {$request->parentNodeId} doesnt exist"); } $created = []; for ($i = 1; $i <= $request->count; $i++) { $created[] = $this->nodeRepo->create(new CreateNodeDto( text: $text, title: "{$request->titlePrefix} {$i}", parentNode: $parentNode, )); } return $created; } }