Cambios a modelo Reservation

This commit is contained in:
Juan Pablo Vial
2025-07-22 18:20:48 -04:00
parent 413709e443
commit 39bc190775
10 changed files with 573 additions and 73 deletions

View File

@ -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;
}
}