36 lines
913 B
PHP
36 lines
913 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Actions\Employee;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use App\Contracts\ActionInputEmpty;
|
|
use App\Models\Employee;
|
|
use App\Services\EmployeeSyncService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<\App\Contracts\ActionInputEmpty, void>
|
|
*/
|
|
final class SynchronizeEmployeesWithArcadiaApi implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly EmployeeSyncService $syncService
|
|
) {
|
|
}
|
|
|
|
/** @param \App\Contracts\ActionInputEmpty $input */
|
|
public function __invoke(ActionInput $input): void
|
|
{
|
|
Assert::isAOf($input, ActionInputEmpty::class);
|
|
|
|
$wasLastSyncedAt = Employee::query()
|
|
->orderBy('last_sync', 'desc')
|
|
->limit(1)
|
|
->first('last_sync')?->last_sync;
|
|
|
|
$this->syncService->synchronize($wasLastSyncedAt);
|
|
}
|
|
}
|