|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Api\Field\Mutation; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Api\Enum\OrderStatusType; |
|
8
|
|
|
use Application\Api\Field\FieldInterface; |
|
9
|
|
|
use Application\Model\Order; |
|
10
|
|
|
use GraphQL\Type\Definition\Type; |
|
11
|
|
|
use Mezzio\Session\SessionInterface; |
|
12
|
|
|
|
|
13
|
|
|
abstract class UpdateOrderStatus implements FieldInterface |
|
14
|
|
|
{ |
|
15
|
1 |
|
public static function build(): array |
|
16
|
|
|
{ |
|
17
|
|
|
return [ |
|
18
|
1 |
|
'name' => 'updateOrderStatus', |
|
19
|
1 |
|
'type' => _types()->getOutput(Order::class), |
|
20
|
1 |
|
'description' => 'Make an order to the shop.', |
|
21
|
|
|
'args' => [ |
|
22
|
1 |
|
'id' => Type::nonNull(_types()->getId(Order::class)), |
|
23
|
1 |
|
'status' => Type::nonNull(_types()->get(OrderStatusType::class)), |
|
|
|
|
|
|
24
|
|
|
], |
|
25
|
|
|
'resolve' => function ($root, array $args, SessionInterface $session): ?Order { |
|
|
|
|
|
|
26
|
|
|
global $container; |
|
27
|
|
|
|
|
28
|
|
|
$status = $args['status']; |
|
29
|
|
|
|
|
30
|
|
|
$order = $args['id']->getEntity(); |
|
31
|
|
|
$order->setStatus($status); |
|
32
|
|
|
|
|
33
|
|
|
// Todo : send notification to customer |
|
34
|
|
|
// |
|
35
|
|
|
// if ($status === Order::STATUS_VALIDATED) { |
|
36
|
|
|
// /** @var Mailer $mailer */ |
|
37
|
|
|
// $mailer = $container->get(Mailer::class); |
|
38
|
|
|
// |
|
39
|
|
|
// /** @var MessageQueuer $messageQueuer */ |
|
40
|
|
|
// $messageQueuer = $container->get(MessageQueuer::class); |
|
41
|
|
|
// |
|
42
|
|
|
// // Notify user |
|
43
|
|
|
// $message = $messageQueuer->queueValidatedOrder($user, $user->getEmail()); |
|
44
|
|
|
// $mailer->sendMessageAsync($message); |
|
45
|
|
|
// } |
|
46
|
|
|
|
|
47
|
|
|
_em()->flush(); |
|
48
|
|
|
_em()->refresh($order); |
|
49
|
|
|
|
|
50
|
|
|
return $order; |
|
51
|
1 |
|
}, |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|