feat(ticketing): add entry reservations management for admin app
- Introduced new routes for entry reservations in admin app, including form, index, store, and download functionalities. - Created a migration to add the "Reserva de Tickets" menu item to the admin app. - Updated MenuSeeder to include the new menu item for ticket reservations. - Developed a PDF view for entry reservations. - Implemented tests for the EntryReservationController and EntryReservationService to ensure proper functionality and access control. - Refactored test setup to use a dedicated schema creation trait for better isolation and maintainability.
This commit is contained in:
@@ -23,6 +23,14 @@ use Illuminate\Validation\ValidationException;
|
||||
/** Application workflow for one ticket per selected catalog item / variant. */
|
||||
class EntryReservationService
|
||||
{
|
||||
private const SELECTION_RELATIONS = [
|
||||
'catalogItem',
|
||||
'variant.catalogItem.itemAttributes.attribute.options',
|
||||
'variant.definitions.itemAttribute.attribute.options',
|
||||
'variant.eventDates',
|
||||
'variant.eventDate',
|
||||
];
|
||||
|
||||
public function __construct(private readonly TicketGeneratorService $tickets) {}
|
||||
|
||||
/**
|
||||
@@ -114,10 +122,21 @@ class EntryReservationService
|
||||
abort_unless($batch->tenant_code === $tenant->codigo && $this->matchesBatch($batch, $rows, $hash),
|
||||
409, 'La clave de envío ya fue utilizada con otra selección.');
|
||||
|
||||
return $batch->reservations()->with(['catalogItem', 'variant', 'ticket'])->orderBy('id')->get();
|
||||
// A scope change must not expose any part of a previously submitted batch.
|
||||
if ($user->event_id !== null) {
|
||||
abort_if($batch->reservations()->withTrashed()
|
||||
->whereDoesntHave('catalogItem', fn (Builder $query) => $query
|
||||
->where('tenant_code', $user->tenant_codigo)
|
||||
->where('event_id', $user->event_id))
|
||||
->exists(), 403);
|
||||
}
|
||||
|
||||
return $batch->reservations()->with([...self::SELECTION_RELATIONS, 'ticket'])->orderBy('id')->get();
|
||||
}
|
||||
|
||||
$items = CatalogItem::query()->forTenantCatalog($tenant)
|
||||
$eventId = $user->event_id ?? $tenant->active_event_id;
|
||||
$items = CatalogItem::query()->where('tenant_code', $tenant->codigo)
|
||||
->when($eventId !== null, fn (Builder $query) => $query->where('event_id', $eventId))
|
||||
->whereKey(array_column($rows, 'catalog_item_id'))->orderBy('id')->lockForUpdate()->get()->keyBy('id');
|
||||
$variants = Variant::query()->whereIn('catalog_item_id', $items->keys())
|
||||
->whereKey(array_filter(array_column($rows, 'variant_id')))
|
||||
@@ -229,7 +248,7 @@ class EntryReservationService
|
||||
->setRelation('catalogItem', $item)->setRelation('variant', $variant));
|
||||
}
|
||||
|
||||
return $reservations;
|
||||
return $reservations->loadMissing(self::SELECTION_RELATIONS);
|
||||
}, 3);
|
||||
}
|
||||
|
||||
@@ -239,11 +258,12 @@ class EntryReservationService
|
||||
abort_unless($user->tenant_codigo !== null && $user->tenant_codigo !== '', 403);
|
||||
|
||||
return EntryReservation::query()
|
||||
->whereHas('catalogItem', fn (Builder $query) => $query->where('tenant_code', $user->tenant_codigo))
|
||||
->whereHas('catalogItem', fn (Builder $query) => $query->where('tenant_code', $user->tenant_codigo)
|
||||
->when($user->event_id !== null, fn (Builder $query) => $query->where('event_id', $user->event_id)))
|
||||
->when($filters['catalog_item_id'] ?? null, fn (Builder $query, int $id) => $query->where('catalog_item_id', $id))
|
||||
->when($filters['variant_id'] ?? null, fn (Builder $query, int $id) => $query->where('variant_id', $id))
|
||||
->when($filters['tipo_pago'] ?? null, fn (Builder $query, string $type) => $query->where('tipo_pago', $type))
|
||||
->with(['catalogItem', 'variant'])
|
||||
->with(self::SELECTION_RELATIONS)
|
||||
->orderByDesc('fecha_reserva')->orderByDesc('id');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user