diff --git a/src/Service/League/updateLeague/HandleUpdateLeague.php b/src/Service/League/updateLeague/HandleUpdateLeague.php index 26e7ffcf..0fef936c 100644 --- a/src/Service/League/updateLeague/HandleUpdateLeague.php +++ b/src/Service/League/updateLeague/HandleUpdateLeague.php @@ -4,6 +4,7 @@ namespace DMD\LaLigaApi\Service\League\updateLeague; use DMD\LaLigaApi\Dto\LeagueDto; use DMD\LaLigaApi\Entity\League; +use DMD\LaLigaApi\Entity\User; use DMD\LaLigaApi\Repository\CustomRoleRepository; use DMD\LaLigaApi\Repository\LeagueRepository; use DMD\LaLigaApi\Repository\UserRepository; @@ -32,8 +33,13 @@ class HandleUpdateLeague { $this->authorizeRequest->authorizeLeaguePresident($leagueId); $user = $this->security->getUser(); + if (!$user instanceof User) + { + throw new HttpException(Response::HTTP_UNAUTHORIZED, 'User not found'); + } $leagueEntity = $this->leagueRepository->find($leagueId); $leagueDto = new LeagueDto(); + $leagueDto->presidentId = $user->getId(); $leagueDto->fillFromObject($leagueEntity); $leagueDto->fillFromArray($request->toArray()); $leagueDto->validate();