Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ListExecutionsQuery | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Automation\Application\Queries; |
| 6 | |
| 7 | use Illuminate\Contracts\Pagination\LengthAwarePaginator; |
| 8 | use ImovelZapAi\Automation\Infrastructure\Persistence\Eloquent\AutomationExecutionModel; |
| 9 | |
| 10 | final class ListExecutionsQuery |
| 11 | { |
| 12 | /** |
| 13 | * @param array{workflow_id?: string, status?: string, per_page?: int} $filters |
| 14 | */ |
| 15 | public function execute(string $tenantId, array $filters = []): LengthAwarePaginator |
| 16 | { |
| 17 | $query = AutomationExecutionModel::query() |
| 18 | ->where('tenant_id', $tenantId) |
| 19 | ->with(['workflow']) |
| 20 | ->orderByDesc('created_at'); |
| 21 | |
| 22 | if (! empty($filters['workflow_id'])) { |
| 23 | $query->where('workflow_id', $filters['workflow_id']); |
| 24 | } |
| 25 | |
| 26 | if (! empty($filters['status'])) { |
| 27 | $query->where('status', $filters['status']); |
| 28 | } |
| 29 | |
| 30 | return $query->paginate((int) ($filters['per_page'] ?? 20)); |
| 31 | } |
| 32 | } |