feat(scanner): return scan attempt result context

This commit is contained in:
2026-09-08 08:51:10 -03:00
parent 34058e6a81
commit 67bcb420e4
5 changed files with 55 additions and 11 deletions

View File

@@ -98,7 +98,7 @@ class ScannerTicketService
return $query->firstOrFail();
}
public function scan(User $scanner, mixed $scannedData): Ticket
public function scan(User $scanner, mixed $scannedData): ScanAttempt
{
$scanAttempt = ScanAttempt::query()->create([
'tenant_code' => $scanner->tenant_codigo,
@@ -125,7 +125,7 @@ class ScannerTicketService
$scanAttempt,
&$ticketId,
&$failureResult,
): Ticket {
): ScanAttempt {
$ticket = $this->baseQuery()
->where('tenant_code', $scanner->tenant_codigo)
->where('ticket', $scannedData)
@@ -172,7 +172,9 @@ class ScannerTicketService
$ticketId,
);
return $ticket->refresh()->load($this->relations());
$ticket = $ticket->refresh()->load($this->relations());
return $scanAttempt->refresh()->setRelation('ticket', $ticket);
});
} catch (Throwable $exception) {
$result = $exception instanceof ModelNotFoundException