- Renamed `desfile_entry_reservations` to `entry_reservations` and `desfile_reservation_batches` to `reservation_batches`. - Updated models, services, and requests to use the new `EntryReservation` model from the `Ticket` domain instead of the deleted `Desfile` model. - Introduced a new `EntryReservationPaymentType` enum to manage payment types. - Modified database migrations to ensure data integrity during the transition. - Updated tests to reflect changes in the database schema and model relationships. - Ensured that existing functionality remains intact while improving code organization and clarity.
49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticketing\Desfile\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class EntryReservationResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
$selection = $this->relationLoaded('variant')
|
|
? $this->variant->selectionOptions()
|
|
: collect();
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'catalog_item_id' => $this->catalog_item_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;
|
|
}
|
|
}
|