PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / User / Customer / UpdateCustomerNoteCommandHandler.php
ameliabooking / src / Application / Commands / User / Customer Last commit date
AddCustomerCommand.php 1 year ago AddCustomerCommandHandler.php 6 months ago GetCustomerCommand.php 1 year ago GetCustomerCommandHandler.php 6 months ago GetCustomersCommand.php 1 year ago GetCustomersCommandHandler.php 2 months ago UpdateCustomerCommand.php 1 year ago UpdateCustomerCommandHandler.php 1 week ago UpdateCustomerNoteCommand.php 3 months ago UpdateCustomerNoteCommandHandler.php 3 months ago UpdateCustomerStatusCommand.php 1 year ago UpdateCustomerStatusCommandHandler.php 6 months ago
UpdateCustomerNoteCommandHandler.php
102 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\User\Customer;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Application\Services\User\UserApplicationService;
9 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
10 use AmeliaBooking\Domain\Entity\Entities;
11 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Repository\User\UserRepository;
14
15 /**
16 * Class UpdateCustomerNoteCommandHandler
17 *
18 * @package AmeliaBooking\Application\Commands\User\Customer
19 */
20 class UpdateCustomerNoteCommandHandler extends CommandHandler
21 {
22 /**
23 * @param UpdateCustomerNoteCommand $command
24 *
25 * @return CommandResult
26 *
27 * @throws InvalidArgumentException
28 * @throws NotFoundException
29 * @throws QueryExecutionException
30 * @throws AccessDeniedException
31 */
32 public function handle(UpdateCustomerNoteCommand $command)
33 {
34 $result = new CommandResult();
35
36 /** @var UserApplicationService $userAS */
37 $userAS = $this->getContainer()->get('application.user.service');
38
39 /** @var UserRepository $userRepository */
40 $userRepository = $this->getContainer()->get('domain.users.repository');
41
42 if (!$command->getPermissionService()->currentUserCanWrite(Entities::CUSTOMERS)) {
43 if ($command->getToken()) {
44 $provider = $command->getCabinetType() === 'provider'
45 ? $userAS->getAuthenticatedUser($command->getToken(), false, 'providerCabinet')
46 : null;
47
48 $oldUser = $provider === null
49 ? $userAS->getAuthenticatedUser($command->getToken(), false, 'customerCabinet')
50 : $userRepository->getById($command->getArg('id'));
51
52 if (
53 $provider === null &&
54 ($oldUser === null || $oldUser->getId()->getValue() !== intval($command->getArg('id')))
55 ) {
56 $result->setResult(CommandResult::RESULT_ERROR);
57 $result->setMessage('Could not retrieve user');
58 $result->setData(['reauthorize' => true]);
59
60 return $result;
61 }
62
63 if ($provider !== null && $oldUser === null) {
64 $result->setResult(CommandResult::RESULT_ERROR);
65 $result->setMessage('Could not retrieve user');
66
67 return $result;
68 }
69 } else {
70 throw new AccessDeniedException('You are not allowed to perform this action!');
71 }
72 } else {
73 $oldUser = $userRepository->getById($command->getArg('id'));
74 if ($oldUser === null) {
75 $result->setResult(CommandResult::RESULT_ERROR);
76 $result->setMessage('Could not retrieve user');
77 return $result;
78 }
79 }
80
81 $customerId = (int)$command->getArg('id');
82 $note = $command->getField('note');
83
84 $userRepository->beginTransaction();
85
86 try {
87 $userRepository->updateFieldById($customerId, $note, 'note');
88 } catch (QueryExecutionException $e) {
89 $userRepository->rollback();
90 throw $e;
91 }
92
93 $userRepository->commit();
94
95 $result->setResult(CommandResult::RESULT_SUCCESS);
96 $result->setMessage('Successfully updated customer note');
97 $result->setData([]);
98
99 return $result;
100 }
101 }
102