@@ 27-84 (lines=58) @@ | ||
24 | use Overblog\GraphQLBundle\Error\UserError; |
|
25 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
26 | ||
27 | class AddMemberToOrganizationMutation implements Mutation |
|
28 | { |
|
29 | private $commandBus; |
|
30 | private $currentUser; |
|
31 | private $organizationResolver; |
|
32 | ||
33 | public function __construct( |
|
34 | TokenStorageInterface $tokenStorage, |
|
35 | CommandBus $commandBus, |
|
36 | OrganizationResolver $organizationResolver |
|
37 | ) { |
|
38 | $this->commandBus = $commandBus; |
|
39 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
40 | $this->organizationResolver = $organizationResolver; |
|
41 | } |
|
42 | ||
43 | public function execute(array $values) : array |
|
44 | { |
|
45 | $command = new AddOrganizationMemberToOrganizationCommand( |
|
46 | $values['userId'], |
|
47 | $values['organizationId'], |
|
48 | $this->currentUser |
|
49 | ); |
|
50 | ||
51 | try { |
|
52 | $this->commandBus->handle($command); |
|
53 | } catch (OrganizationDoesNotExistException $exception) { |
|
54 | throw new UserError( |
|
55 | sprintf( |
|
56 | 'The organization with "%s" id does not exist', |
|
57 | $values['organizationId'] |
|
58 | ) |
|
59 | ); |
|
60 | } catch (UnauthorizedOrganizationActionException $exception) { |
|
61 | throw new UserError( |
|
62 | sprintf( |
|
63 | 'The "%s" user does not allow to edit the organization', |
|
64 | $this->currentUser |
|
65 | ) |
|
66 | ); |
|
67 | } catch (UserDoesNotExistException $exception) { |
|
68 | throw new UserError( |
|
69 | sprintf( |
|
70 | 'The user with "%s" id does not exist', |
|
71 | $values['userId'] |
|
72 | ) |
|
73 | ); |
|
74 | } |
|
75 | ||
76 | $organization = $this->organizationResolver->resolve([ |
|
77 | 'id' => $values['organizationId'], |
|
78 | ]); |
|
79 | ||
80 | return [ |
|
81 | 'organization' => $organization, |
|
82 | ]; |
|
83 | } |
|
84 | } |
|
85 |
@@ 27-84 (lines=58) @@ | ||
24 | use Overblog\GraphQLBundle\Error\UserError; |
|
25 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
26 | ||
27 | class EditOrganizationMutation implements Mutation |
|
28 | { |
|
29 | private $commandBus; |
|
30 | private $currentUser; |
|
31 | private $organizationResolver; |
|
32 | ||
33 | public function __construct( |
|
34 | TokenStorageInterface $tokenStorage, |
|
35 | CommandBus $commandBus, |
|
36 | OrganizationResolver $organizationResolver |
|
37 | ) { |
|
38 | $this->commandBus = $commandBus; |
|
39 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
40 | $this->organizationResolver = $organizationResolver; |
|
41 | } |
|
42 | ||
43 | public function execute(array $values) : array |
|
44 | { |
|
45 | $command = new EditOrganizationCommand( |
|
46 | $values['id'], |
|
47 | $values['name'], |
|
48 | $this->currentUser |
|
49 | ); |
|
50 | ||
51 | try { |
|
52 | $this->commandBus->handle($command); |
|
53 | } catch (OrganizationAlreadyExistsException $exception) { |
|
54 | throw new UserError( |
|
55 | sprintf( |
|
56 | 'The organization with "%s" name already exists', |
|
57 | $values['name'] |
|
58 | ) |
|
59 | ); |
|
60 | } catch (OrganizationDoesNotExistException $exception) { |
|
61 | throw new UserError( |
|
62 | sprintf( |
|
63 | 'The organization with "%s" id does not exist', |
|
64 | $values['id'] |
|
65 | ) |
|
66 | ); |
|
67 | } catch (UnauthorizedEditOrganizationException $exception) { |
|
68 | throw new UserError( |
|
69 | sprintf( |
|
70 | 'The "%s" user does not allow to edit the organization', |
|
71 | $this->currentUser |
|
72 | ) |
|
73 | ); |
|
74 | } |
|
75 | ||
76 | $organization = $this->organizationResolver->resolve([ |
|
77 | 'id' => $command->id(), |
|
78 | ]); |
|
79 | ||
80 | return [ |
|
81 | 'organization' => $organization, |
|
82 | ]; |
|
83 | } |
|
84 | } |
|
85 |
@@ 27-84 (lines=58) @@ | ||
24 | use Overblog\GraphQLBundle\Error\UserError; |
|
25 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
26 | ||
27 | class RemoveMemberToOrganizationMutation implements Mutation |
|
28 | { |
|
29 | private $commandBus; |
|
30 | private $currentUser; |
|
31 | private $organizationResolver; |
|
32 | ||
33 | public function __construct( |
|
34 | TokenStorageInterface $tokenStorage, |
|
35 | CommandBus $commandBus, |
|
36 | OrganizationResolver $organizationResolver |
|
37 | ) { |
|
38 | $this->commandBus = $commandBus; |
|
39 | $this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
40 | $this->organizationResolver = $organizationResolver; |
|
41 | } |
|
42 | ||
43 | public function execute(array $values) : array |
|
44 | { |
|
45 | $command = new RemoveOrganizationMemberToOrganizationCommand( |
|
46 | $values['userId'], |
|
47 | $values['organizationId'], |
|
48 | $this->currentUser |
|
49 | ); |
|
50 | ||
51 | try { |
|
52 | $this->commandBus->handle($command); |
|
53 | } catch (OrganizationDoesNotExistException $exception) { |
|
54 | throw new UserError( |
|
55 | sprintf( |
|
56 | 'The organization with "%s" id does not exist', |
|
57 | $values['organizationId'] |
|
58 | ) |
|
59 | ); |
|
60 | } catch (UnauthorizedOrganizationActionException $exception) { |
|
61 | throw new UserError( |
|
62 | sprintf( |
|
63 | 'The "%s" user does not allow to edit the organization', |
|
64 | $this->currentUser |
|
65 | ) |
|
66 | ); |
|
67 | } catch (UserDoesNotExistException $exception) { |
|
68 | throw new UserError( |
|
69 | sprintf( |
|
70 | 'The user with "%s" id does not exist', |
|
71 | $values['userId'] |
|
72 | ) |
|
73 | ); |
|
74 | } |
|
75 | ||
76 | $organization = $this->organizationResolver->resolve([ |
|
77 | 'id' => $values['organizationId'], |
|
78 | ]); |
|
79 | ||
80 | return [ |
|
81 | 'organization' => $organization, |
|
82 | ]; |
|
83 | } |
|
84 | } |
|
85 |