inti project
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use App\Domain\SchoolCore\Attendance\DTO\ProcessScanData;
|
||||
use DateTimeImmutable;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final class ProcessScanRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'badge_value' => ['required', 'string', 'max:191'],
|
||||
'station_id' => ['nullable', 'string', 'max:191'],
|
||||
'scan_action' => ['nullable', 'string', 'in:check_in,check_out,lookup'],
|
||||
'scan_source' => ['nullable', 'string', 'in:scanner,manual,api'],
|
||||
'scanned_at' => ['nullable', 'date'],
|
||||
'device_id' => ['nullable', 'string', 'max:191'],
|
||||
'client_request_id' => ['nullable', 'string', 'max:191'],
|
||||
'idempotency_key' => ['nullable', 'string', 'max:191'],
|
||||
'metadata' => ['nullable', 'array'],
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(): ProcessScanData
|
||||
{
|
||||
$validated = $this->validated();
|
||||
|
||||
return new ProcessScanData(
|
||||
badgeValue: (string) $validated['badge_value'],
|
||||
stationId: $validated['station_id'] ?? null,
|
||||
scanAction: $validated['scan_action'] ?? 'check_in',
|
||||
scanSource: $validated['scan_source'] ?? 'scanner',
|
||||
scannedAt: new DateTimeImmutable($validated['scanned_at'] ?? 'now'),
|
||||
deviceId: $validated['device_id'] ?? null,
|
||||
clientRequestId: $validated['client_request_id'] ?? null,
|
||||
idempotencyKey: $validated['idempotency_key'] ?? null,
|
||||
metadata: $validated['metadata'] ?? [],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user