security->getUser(); if (!$leagueAdminEntity instanceof User) { throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, 'Internal Server Error'); } $this->authorizeRequest->isLeaguePresident($leagueId, $leagueAdminEntity); $leagueEntity = $this->leagueRepository->find($leagueId); if (is_null($leagueEntity)) { throw new HttpException(Response::HTTP_NOT_FOUND, "Liga con id $leagueId no ha sido encontrada"); } $requestingUserEntity = $this->userRepository->find($userId); if (is_null($requestingUserEntity)) { throw new HttpException(Response::HTTP_NOT_FOUND,"El usuario con id: $userId no ha sido encontrado."); } $customRoleEntity = new CustomRole(); $customRoleEntity->setName(Role::LEAGUE_MEMBER->value); $customRoleEntity->setEntityId($leagueId); $customRoleEntity->setUser($requestingUserEntity); $this->entityManager->persist($customRoleEntity); $this->entityManager->flush(); $this->emailSender->joinLeagueRequestAccepted( $requestingUserEntity, $leagueEntity ); return new JsonResponse( data: [ 'success' => true, ], status: Response::HTTP_OK ); } }