| @@ 26-74 (lines=49) @@ | ||
| 23 | use Overblog\GraphQLBundle\Error\UserError; |
|
| 24 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
| 25 | ||
| 26 | class OrganizationMemberResolver implements Resolver |
|
| 27 | { |
|
| 28 | private $queryBus; |
|
| 29 | private $currentUser; |
|
| 30 | ||
| 31 | public function __construct(TokenStorageInterface $tokenStorage, QueryBus $queryBus) |
|
| 32 | { |
|
| 33 | $this->queryBus = $queryBus; |
|
| 34 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
| 35 | } |
|
| 36 | ||
| 37 | public function resolve($args) |
|
| 38 | { |
|
| 39 | try { |
|
| 40 | $this->queryBus->handle( |
|
| 41 | new OrganizationMemberOfIdQuery( |
|
| 42 | $args['organizationId'], |
|
| 43 | $args['organizationMemberId'], |
|
| 44 | $this->currentUser |
|
| 45 | ), |
|
| 46 | $result |
|
| 47 | ); |
|
| 48 | ||
| 49 | return $result; |
|
| 50 | } catch (OrganizationDoesNotExistException $exception) { |
|
| 51 | throw new UserError( |
|
| 52 | sprintf( |
|
| 53 | 'Does not exist any organization with the given "%s" id', |
|
| 54 | $args['organizationId'] |
|
| 55 | ) |
|
| 56 | ); |
|
| 57 | } catch (UnauthorizedOrganizationActionException $exception) { |
|
| 58 | throw new UserError( |
|
| 59 | sprintf( |
|
| 60 | 'The "%s" user does not allow to access the "%s" organization', |
|
| 61 | $this->currentUser, |
|
| 62 | $args['organizationId'] |
|
| 63 | ) |
|
| 64 | ); |
|
| 65 | } catch (OrganizationMemberDoesNotExistException $exception) { |
|
| 66 | throw new UserError( |
|
| 67 | sprintf( |
|
| 68 | 'Does not exist any organization member with the given "%s" id', |
|
| 69 | $args['organizationMemberId'] |
|
| 70 | ) |
|
| 71 | ); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||
| @@ 26-74 (lines=49) @@ | ||
| 23 | use Overblog\GraphQLBundle\Error\UserError; |
|
| 24 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
| 25 | ||
| 26 | class OwnerResolver implements Resolver |
|
| 27 | { |
|
| 28 | private $queryBus; |
|
| 29 | private $currentUser; |
|
| 30 | ||
| 31 | public function __construct(TokenStorageInterface $tokenStorage, QueryBus $queryBus) |
|
| 32 | { |
|
| 33 | $this->queryBus = $queryBus; |
|
| 34 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
| 35 | } |
|
| 36 | ||
| 37 | public function resolve($args) |
|
| 38 | { |
|
| 39 | try { |
|
| 40 | $this->queryBus->handle( |
|
| 41 | new OwnerOfIdQuery( |
|
| 42 | $args['organizationId'], |
|
| 43 | $args['ownerId'], |
|
| 44 | $this->currentUser |
|
| 45 | ), |
|
| 46 | $result |
|
| 47 | ); |
|
| 48 | ||
| 49 | return $result; |
|
| 50 | } catch (OrganizationDoesNotExistException $exception) { |
|
| 51 | throw new UserError( |
|
| 52 | sprintf( |
|
| 53 | 'Does not exist any organization with the given "%s" id', |
|
| 54 | $args['organizationId'] |
|
| 55 | ) |
|
| 56 | ); |
|
| 57 | } catch (UnauthorizedOrganizationActionException $exception) { |
|
| 58 | throw new UserError( |
|
| 59 | sprintf( |
|
| 60 | 'The "%s" user does not allow to access the "%s" organization', |
|
| 61 | $this->currentUser, |
|
| 62 | $args['organizationId'] |
|
| 63 | ) |
|
| 64 | ); |
|
| 65 | } catch (OwnerDoesNotExistException $exception) { |
|
| 66 | throw new UserError( |
|
| 67 | sprintf( |
|
| 68 | 'Does not exist any owner with the given "%s" id', |
|
| 69 | $args['ownerId'] |
|
| 70 | ) |
|
| 71 | ); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||