Cambios a modelo Reservation
This commit is contained in:
@ -14,7 +14,9 @@ use Incoviba\Repository;
|
||||
|
||||
class Reservation extends Ideal\Service\API
|
||||
{
|
||||
public function __construct(LoggerInterface $logger, protected Repository\Venta\Reservation $reservationRepository)
|
||||
public function __construct(LoggerInterface $logger,
|
||||
protected Repository\Venta\Reservation $reservationRepository,
|
||||
protected Repository\Venta\Reservation\State $stateRepository)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
}
|
||||
@ -22,7 +24,7 @@ class Reservation extends Ideal\Service\API
|
||||
public function getAll(null|string|array $order = null): array
|
||||
{
|
||||
try {
|
||||
return $this->reservationRepository->fetchAll($order);
|
||||
return array_map([$this, 'process'], $this->reservationRepository->fetchAll($order));
|
||||
} catch (Implement\Exception\EmptyResult) {
|
||||
return [];
|
||||
}
|
||||
@ -76,6 +78,12 @@ class Reservation extends Ideal\Service\API
|
||||
}
|
||||
protected function process(Define\Model $model): Model\Venta\Reservation
|
||||
{
|
||||
$model->addFactory('states', new Implement\Repository\Factory()
|
||||
->setArgs(['reservation_id' => $model->id])
|
||||
->setCallable(function(int $reservation_id) {
|
||||
return $this->stateRepository->fetchByReservation($reservation_id);
|
||||
})
|
||||
);
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user