feat(ticket): implement DesfileEntryReservationController and related services for ticket reservations
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user