feat(desfile): cancel entry reservations
This commit is contained in:
@@ -71,6 +71,41 @@ class EntryReservationService
|
||||
return $reservation->ticket;
|
||||
}
|
||||
|
||||
public function cancel(User $user, int $reservationId): void
|
||||
{
|
||||
abort_unless($user->tenant_codigo === 'desfile_pura_tendencia', 403);
|
||||
|
||||
DB::transaction(function () use ($user, $reservationId): void {
|
||||
$reservation = EntryReservation::query()
|
||||
->whereKey($reservationId)
|
||||
->whereHas('variant.catalogItem', fn (Builder $query): Builder => $query
|
||||
->where('tenant_code', $user->tenant_codigo)
|
||||
->where('slug', 'entrada'))
|
||||
->lockForUpdate()
|
||||
->firstOrFail();
|
||||
|
||||
if ($reservation->ticket_id !== null) {
|
||||
$ticket = Ticket::query()->lockForUpdate()->findOrFail($reservation->ticket_id);
|
||||
|
||||
if (! $ticket->can_cancel()) {
|
||||
throw ValidationException::withMessages([
|
||||
'status' => 'El ticket debe estar activo para poder cancelar la reserva.',
|
||||
]);
|
||||
}
|
||||
|
||||
$ticket->markAsCancelled();
|
||||
$ticket->save();
|
||||
}
|
||||
|
||||
if ($reservation->inventory_id !== null) {
|
||||
$inventory = Inventory::query()->lockForUpdate()->findOrFail($reservation->inventory_id);
|
||||
$inventory->releaseEntry(1);
|
||||
}
|
||||
|
||||
$reservation->delete();
|
||||
}, 3);
|
||||
}
|
||||
|
||||
/** @param array{tipo_pago?: string|null} $filters */
|
||||
private function reservationsQuery(User $user, array $filters = []): Builder
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user