add null guards in bulk create nodes use case

This commit is contained in:
Yisroel Baum 2026-04-19 23:10:10 +03:00
parent 337017fc52
commit 1f76fc08b6
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -2,6 +2,7 @@
namespace App\Node\UseCases; namespace App\Node\UseCases;
use App\Exceptions\BadRequestException;
use App\Node\CreateNodeDto; use App\Node\CreateNodeDto;
use App\Node\Node; use App\Node\Node;
use App\Node\NodeRepository; use App\Node\NodeRepository;
@ -21,6 +22,22 @@ class BulkCreateNodes
*/ */
public function execute(BulkCreateNodesRequest $request): array public function execute(BulkCreateNodesRequest $request): array
{ {
if ($request->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');
}
$text = $this->textRepo->find($request->textId); $text = $this->textRepo->find($request->textId);
if ($text === null) { if ($text === null) {
throw new DomainException("Text with id: {$request->textId} doesnt exist"); throw new DomainException("Text with id: {$request->textId} doesnt exist");