Skip to content

Commit

Permalink
soucasne mazani lidi... problem s constrainty
Browse files Browse the repository at this point in the history
  • Loading branch information
bojovyletoun committed Dec 15, 2022
1 parent 24d5fc5 commit a27325a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/Model/User/Commands/Handlers/DeletePatrolHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Model\User\Queries\PatrolByIdQuery;
use App\Model\User\Repositories\PatrolRepository;
use App\Model\User\Repositories\UserGroupRoleRepository;
use App\Model\User\Repositories\UserRepository;
use App\Services\QueryBus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
Expand All @@ -18,7 +19,8 @@ public function __construct(
private QueryBus $queryBus,
private EntityManagerInterface $em,
private PatrolRepository $patrolRepository,
private UserGroupRoleRepository $userGroupRoleRepository
private UserGroupRoleRepository $userGroupRoleRepository,
private UserRepository $userRepository
) {
}

Expand All @@ -28,6 +30,11 @@ public function __invoke(DeletePatrol $command): void
$patrol = $this->queryBus->handle(new PatrolByIdQuery($command->id));
foreach ($patrol->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
$u = $usersRole->getUser();
// $r = $u->getRoles();
if ($u->getRolesText() == '') {
$this->userRepository->remove($u);
}
}

$this->patrolRepository->remove($patrol);
Expand Down
9 changes: 8 additions & 1 deletion app/Model/User/Commands/Handlers/DeleteTroopHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Model\User\Queries\TroopByIdQuery;
use App\Model\User\Repositories\TroopRepository;
use App\Model\User\Repositories\UserGroupRoleRepository;
use App\Model\User\Repositories\UserRepository;
use App\Services\CommandBus;
use App\Services\QueryBus;
use Doctrine\ORM\EntityManagerInterface;
Expand All @@ -21,7 +22,8 @@ public function __construct(
private CommandBus $commandBus,
private EntityManagerInterface $em,
private TroopRepository $troopRepository,
private UserGroupRoleRepository $userGroupRoleRepository
private UserGroupRoleRepository $userGroupRoleRepository,
private UserRepository $userRepository
) {
}

Expand All @@ -35,6 +37,11 @@ public function __invoke(DeleteTroop $command): void

foreach ($troop->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
$u = $usersRole->getUser();

if ($u->getRolesText() == '') {
$this->userRepository->remove($usersRole->getUser());
}
}

$this->troopRepository->remove($troop);
Expand Down

0 comments on commit a27325a

Please sign in to comment.