Adds UpdateCustomer action, input, and output classes to handle customer information updates. Integrates with existing services and updates the CustomerController to utilize the new action.
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Crm;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use App\Services\CrmService;
|
|
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<\App\Actions\Crm\UpdateCustomerInput, \App\Actions\Crm\UpdateCustomerOutput>
|
|
*/
|
|
final class UpdateCustomer implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly AppCustomerAuthService $authService,
|
|
private readonly CrmService $crmService
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function __invoke(ActionInput $input): UpdateCustomerOutput
|
|
{
|
|
Assert::isInstanceOf($input, UnsubscribeFromNewsletterInput::class);
|
|
|
|
$customer = $this->authService->getCustomerAsMandatory();
|
|
|
|
try {
|
|
$result = $this->crmService->updateCustomerInfos(
|
|
$customer,
|
|
[
|
|
'firstname' => $input->firstname,
|
|
'lastname' => $input->lastname,
|
|
'birth_date' => $input->birthDate,
|
|
'phone' => $input->phone,
|
|
'address' => $input->address,
|
|
'postcode' => $input->postcode,
|
|
'city' => $input->city,
|
|
'opt_in' => $input->optIn,
|
|
]
|
|
);
|
|
|
|
return new UpdateCustomerOutput($result);
|
|
} catch (\Throwable $e) {
|
|
report($e);
|
|
|
|
return new UpdateCustomerOutput(false);
|
|
}
|
|
}
|
|
}
|