ameliabooking
/
src
/
Application
/
Commands
/
Booking
/
Appointment
/
UpdateAppointmentNoteCommandHandler.php
AddAppointmentCommand.php
1 year ago
AddAppointmentCommandHandler.php
2 months ago
AddBookingCommand.php
1 year ago
AddBookingCommandHandler.php
1 year ago
ApproveBookingRemotelyCommand.php
1 year ago
ApproveBookingRemotelyCommandHandler.php
2 months ago
CancelBookingCommand.php
1 year ago
CancelBookingCommandHandler.php
6 months ago
CancelBookingRemotelyCommand.php
1 year ago
CancelBookingRemotelyCommandHandler.php
1 month ago
DeleteAppointmentCommand.php
1 year ago
DeleteAppointmentCommandHandler.php
1 year ago
DeleteBookingCommand.php
1 year ago
DeleteBookingCommandHandler.php
10 months ago
DeleteBookingRemotelyCommand.php
10 months ago
DeleteBookingRemotelyCommandHandler.php
6 months ago
GetAppointmentBookingsCommand.php
6 months ago
GetAppointmentBookingsCommandHandler.php
2 months ago
GetAppointmentCommand.php
7 years ago
GetAppointmentCommandHandler.php
2 weeks ago
GetAppointmentsCommand.php
1 year ago
GetAppointmentsCommandHandler.php
2 weeks ago
GetIcsCommand.php
6 months ago
GetIcsCommandHandler.php
4 years ago
GetTimeSlotsCommand.php
1 year ago
GetTimeSlotsCommandHandler.php
1 month ago
ReassignBookingCommand.php
1 year ago
ReassignBookingCommandHandler.php
3 months ago
RejectBookingRemotelyCommand.php
1 year ago
RejectBookingRemotelyCommandHandler.php
4 months ago
SuccessfulBookingCommand.php
1 year ago
SuccessfulBookingCommandHandler.php
1 year ago
UpdateAppointmentCommand.php
1 year ago
UpdateAppointmentCommandHandler.php
3 months ago
UpdateAppointmentNoteCommand.php
3 months ago
UpdateAppointmentNoteCommandHandler.php
3 months ago
UpdateAppointmentStatusCommand.php
1 year ago
UpdateAppointmentStatusCommandHandler.php
2 months ago
UpdateAppointmentTimeCommand.php
1 year ago
UpdateAppointmentTimeCommandHandler.php
1 month ago
UpdateBookingStatusCommand.php
1 year ago
UpdateBookingStatusCommandHandler.php
5 months ago
UpdateAppointmentNoteCommandHandler.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Booking\Appointment; |
| 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\AuthorizationException; |
| 10 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 11 | use AmeliaBooking\Domain\Entity\Entities; |
| 12 | use AmeliaBooking\Domain\Entity\User\AbstractUser; |
| 13 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 14 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 15 | use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\AppointmentRepository; |
| 16 | |
| 17 | /** |
| 18 | * Class UpdateAppointmentNoteCommandHandler |
| 19 | * |
| 20 | * @package AmeliaBooking\Application\Commands\Booking\Appointment |
| 21 | */ |
| 22 | class UpdateAppointmentNoteCommandHandler extends CommandHandler |
| 23 | { |
| 24 | /** |
| 25 | * @param UpdateAppointmentNoteCommand $command |
| 26 | * |
| 27 | * @return CommandResult |
| 28 | * @throws AccessDeniedException |
| 29 | * @throws AuthorizationException |
| 30 | * @throws InvalidArgumentException |
| 31 | * @throws QueryExecutionException |
| 32 | */ |
| 33 | public function handle(UpdateAppointmentNoteCommand $command) |
| 34 | { |
| 35 | $result = new CommandResult(); |
| 36 | |
| 37 | /** @var UserApplicationService $userAS */ |
| 38 | $userAS = $this->getContainer()->get('application.user.service'); |
| 39 | /** @var SettingsService $settingsDS */ |
| 40 | $settingsDS = $this->container->get('domain.settings.service'); |
| 41 | /** @var AppointmentRepository $appointmentRepo */ |
| 42 | $appointmentRepo = $this->container->get('domain.booking.appointment.repository'); |
| 43 | |
| 44 | try { |
| 45 | /** @var AbstractUser $user */ |
| 46 | $user = $command->getUserApplicationService()->authorization( |
| 47 | $command->getPage() === 'cabinet' ? $command->getToken() : null, |
| 48 | $command->getCabinetType() |
| 49 | ); |
| 50 | } catch (AuthorizationException $e) { |
| 51 | $result->setResult(CommandResult::RESULT_ERROR); |
| 52 | $result->setData(['reauthorize' => true]); |
| 53 | |
| 54 | return $result; |
| 55 | } |
| 56 | |
| 57 | if ($userAS->isCustomer($user)) { |
| 58 | throw new AccessDeniedException('You are not allowed to update appointment'); |
| 59 | } |
| 60 | |
| 61 | if ($userAS->isProvider($user) && !$settingsDS->getSetting('roles', 'allowWriteAppointments')) { |
| 62 | throw new AccessDeniedException('You are not allowed to update appointment'); |
| 63 | } |
| 64 | |
| 65 | $appointmentId = (int)$command->getArg('id'); |
| 66 | $note = $command->getField('internalNotes'); |
| 67 | $oldAppointment = $appointmentRepo->getById($appointmentId); |
| 68 | |
| 69 | if ($oldAppointment === null) { |
| 70 | $result->setResult(CommandResult::RESULT_ERROR); |
| 71 | $result->setMessage('Appointment not found'); |
| 72 | return $result; |
| 73 | } |
| 74 | |
| 75 | $appointmentRepo->updateFieldById($appointmentId, $note, 'internalNotes'); |
| 76 | |
| 77 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 78 | $result->setMessage('Successfully updated appointment note'); |
| 79 | $result->setData([ |
| 80 | Entities::APPOINTMENT => array_merge( |
| 81 | $oldAppointment->toArray(), |
| 82 | ['internalNotes' => $note] |
| 83 | ), |
| 84 | ]); |
| 85 | |
| 86 | return $result; |
| 87 | } |
| 88 | } |
| 89 |