Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
GetBrokerAgendaQuery
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 execute
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace ImovelZapAi\Visits\Application\Queries;
6
7use Carbon\Carbon;
8use Illuminate\Support\Collection;
9use ImovelZapAi\Visits\Domain\Enums\VisitStatus;
10use ImovelZapAi\Visits\Infrastructure\Persistence\Eloquent\VisitModel;
11
12final class GetBrokerAgendaQuery
13{
14    /**
15     * @return Collection<int, VisitModel>
16     */
17    public function execute(
18        string $tenantId,
19        int $brokerUserId,
20        ?Carbon $from = null,
21        ?Carbon $to = null,
22    ): Collection {
23        $from ??= now()->startOfDay();
24        $to ??= now()->addDays(7)->endOfDay();
25
26        return VisitModel::query()
27            ->where('tenant_id', $tenantId)
28            ->where('responsible_user_id', $brokerUserId)
29            ->whereNotIn('status', [VisitStatus::Cancelled])
30            ->whereBetween('scheduled_start', [$from, $to])
31            ->with(['contact', 'property'])
32            ->orderBy('scheduled_start')
33            ->get();
34    }
35}