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