Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
36 / 36 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CompleteDocumentScanAction | |
100.00% |
36 / 36 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\ClientPortal\Application\Actions; |
| 6 | |
| 7 | use Illuminate\Support\Facades\DB; |
| 8 | use ImovelZapAi\ClientPortal\Application\Services\PortalActivityWriter; |
| 9 | use ImovelZapAi\ClientPortal\Domain\Enums\DocumentScanStatus; |
| 10 | use ImovelZapAi\ClientPortal\Domain\Enums\PortalActivityEvent; |
| 11 | use ImovelZapAi\ClientPortal\Domain\Enums\RequestedDocumentStatus; |
| 12 | use ImovelZapAi\ClientPortal\Infrastructure\Persistence\Eloquent\UploadedDocumentModel; |
| 13 | |
| 14 | final class CompleteDocumentScanAction |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly PortalActivityWriter $activity, |
| 18 | ) {} |
| 19 | |
| 20 | public function execute(string $uploadedDocumentId, bool $infected = false): void |
| 21 | { |
| 22 | DB::transaction(function () use ($uploadedDocumentId, $infected): void { |
| 23 | $upload = UploadedDocumentModel::query()->whereKey($uploadedDocumentId)->first(); |
| 24 | if ($upload === null) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if ($infected) { |
| 29 | $upload->forceFill([ |
| 30 | 'scan_status' => DocumentScanStatus::Infected, |
| 31 | 'status' => 'rejected', |
| 32 | ])->save(); |
| 33 | $upload->requestedDocument?->forceFill([ |
| 34 | 'status' => RequestedDocumentStatus::Rejected, |
| 35 | ])->save(); |
| 36 | |
| 37 | $this->activity->write( |
| 38 | $upload->tenant_id, |
| 39 | $upload->client_portal_id, |
| 40 | PortalActivityEvent::ScanCompleted, |
| 41 | message: 'Arquivo bloqueado na verificação de segurança.', |
| 42 | payload: ['uploaded_document_id' => $upload->id, 'infected' => true], |
| 43 | ); |
| 44 | |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | $upload->forceFill([ |
| 49 | 'scan_status' => DocumentScanStatus::Clean, |
| 50 | 'status' => 'under_review', |
| 51 | ])->save(); |
| 52 | |
| 53 | $upload->requestedDocument?->forceFill([ |
| 54 | 'status' => RequestedDocumentStatus::UnderReview, |
| 55 | ])->save(); |
| 56 | |
| 57 | $this->activity->write( |
| 58 | $upload->tenant_id, |
| 59 | $upload->client_portal_id, |
| 60 | PortalActivityEvent::ScanCompleted, |
| 61 | message: 'Verificação de segurança concluída.', |
| 62 | payload: ['uploaded_document_id' => $upload->id, 'infected' => false], |
| 63 | ); |
| 64 | }); |
| 65 | } |
| 66 | } |