Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| DealActivityRecorder | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| record | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Sales\Application\Services; |
| 6 | |
| 7 | use ImovelZapAi\Sales\Domain\Enums\DealActivityType; |
| 8 | use ImovelZapAi\Sales\Infrastructure\Persistence\Eloquent\DealActivityModel; |
| 9 | use ImovelZapAi\Sales\Infrastructure\Persistence\Eloquent\DealModel; |
| 10 | |
| 11 | final class DealActivityRecorder |
| 12 | { |
| 13 | /** |
| 14 | * @param array<string, mixed>|null $meta |
| 15 | */ |
| 16 | public function record( |
| 17 | DealModel $deal, |
| 18 | DealActivityType $type, |
| 19 | string $title, |
| 20 | ?string $body = null, |
| 21 | ?int $actorUserId = null, |
| 22 | ?array $meta = null, |
| 23 | ): DealActivityModel { |
| 24 | $activity = DealActivityModel::query()->create([ |
| 25 | 'tenant_id' => $deal->tenant_id, |
| 26 | 'deal_id' => $deal->id, |
| 27 | 'actor_user_id' => $actorUserId, |
| 28 | 'type' => $type, |
| 29 | 'title' => $title, |
| 30 | 'body' => $body, |
| 31 | 'meta' => $meta, |
| 32 | 'occurred_at' => now(), |
| 33 | ]); |
| 34 | |
| 35 | $deal->forceFill(['last_activity_at' => now()])->save(); |
| 36 | |
| 37 | return $activity; |
| 38 | } |
| 39 | } |