|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Kreta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Kreta\TaskManager\Infrastructure\Ui\Http\GraphQl\Query\Organization; |
|
16
|
|
|
|
|
17
|
|
|
use Kreta\SharedKernel\Application\QueryBus; |
|
18
|
|
|
use Kreta\SharedKernel\Http\GraphQl\Resolver; |
|
19
|
|
|
use Kreta\TaskManager\Application\Query\Organization\OrganizationMemberOfIdQuery; |
|
20
|
|
|
use Kreta\TaskManager\Application\Query\Organization\OwnerOfIdQuery; |
|
21
|
|
|
use Kreta\TaskManager\Domain\Model\Organization\OwnerDoesNotExistException; |
|
22
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
23
|
|
|
|
|
24
|
|
|
class MemberResolver implements Resolver |
|
25
|
|
|
{ |
|
26
|
|
|
private $queryBus; |
|
27
|
|
|
private $currentUser; |
|
28
|
|
|
private $organizationResolver; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
TokenStorageInterface $tokenStorage, |
|
32
|
|
|
QueryBus $queryBus, |
|
33
|
|
|
OrganizationResolver $organizationResolver |
|
34
|
|
|
) { |
|
35
|
|
|
$this->queryBus = $queryBus; |
|
36
|
|
|
$this->currentUser = $tokenStorage->getToken()->getUser()->getUsername(); |
|
37
|
|
|
$this->organizationResolver = $organizationResolver; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function resolve($args) |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
$this->queryBus->handle( |
|
44
|
|
|
new OwnerOfIdQuery( |
|
45
|
|
|
$args['organizationId'], |
|
46
|
|
|
$args['ownerId'], |
|
47
|
|
|
$this->currentUser |
|
48
|
|
|
), |
|
49
|
|
|
$result |
|
50
|
|
|
); |
|
51
|
|
|
} catch (OwnerDoesNotExistException $exception) { |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (empty($result)) { |
|
55
|
|
|
$this->queryBus->handle( |
|
56
|
|
|
new OrganizationMemberOfIdQuery( |
|
57
|
|
|
$args['organizationId'], |
|
58
|
|
|
$args['organizationMemberId'], |
|
59
|
|
|
$this->currentUser |
|
60
|
|
|
), |
|
61
|
|
|
$result |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$result['organization'] = $this->organizationResolver->resolve([ |
|
66
|
|
|
'id' => $args['organizationId'], |
|
67
|
|
|
]); |
|
68
|
|
|
|
|
69
|
|
|
return $result; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|