feat(desfile): list paginated entry reservations
This commit is contained in:
@@ -9,13 +9,39 @@ class EntryReservationResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$selection = $this->relationLoaded('variant')
|
||||
? $this->variant->selectionOptions()
|
||||
: collect();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'variant_id' => $this->variant_id,
|
||||
'ticket_id' => $this->ticket_id,
|
||||
'fecha_reserva' => $this->fecha_reserva->toIso8601String(),
|
||||
'tipo_pago' => $this->tipo_pago->value,
|
||||
'tipo_pago_label' => $this->tipo_pago->label(),
|
||||
'importe' => $this->importe,
|
||||
'entrada' => [
|
||||
'tipo' => $this->selectionLabel($selection->get('tipo')),
|
||||
'sector' => $this->selectionLabel($selection->get('sector')),
|
||||
'fila' => $this->selectionLabel($selection->get('fila')),
|
||||
'asiento' => $this->selectionLabel($selection->get('asiento')),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function selectionLabel(mixed $selection): ?string
|
||||
{
|
||||
if (! is_array($selection)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_is_list($selection)) {
|
||||
$labels = collect($selection)->pluck('label')->filter()->implode(', ');
|
||||
|
||||
return $labels !== '' ? $labels : null;
|
||||
}
|
||||
|
||||
return isset($selection['label']) ? (string) $selection['label'] : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user