32 lines
977 B
PHP
32 lines
977 B
PHP
<?php
|
|
|
|
namespace App\Domains\Ticketing\Desfile\Services;
|
|
|
|
use App\Domains\Ticketing\Ticket\Services\EntryReservationPolicy;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class DesfileEntryReservationPolicy implements EntryReservationPolicy
|
|
{
|
|
public function validate(array $selections): void
|
|
{
|
|
$errors = [];
|
|
$seen = [];
|
|
|
|
foreach ($selections as $index => $selection) {
|
|
$variant = $selection['variant'];
|
|
if ($variant === null || $selection['inventory'] === null
|
|
|| isset($seen[$variant->id])
|
|
|| $variant->entryReservations()->lockForUpdate()->get()->isNotEmpty()) {
|
|
$errors["rows.{$index}.variant_id"] = 'La entrada ya no está disponible.';
|
|
}
|
|
if ($variant !== null) {
|
|
$seen[$variant->id] = true;
|
|
}
|
|
}
|
|
|
|
if ($errors !== []) {
|
|
throw ValidationException::withMessages($errors);
|
|
}
|
|
}
|
|
}
|