Optimizacion de queries a cargar de una sola vez

This commit is contained in:
Juan Pablo Vial
2025-04-22 09:28:12 -04:00
parent fc776e6cec
commit 33b4182bd3
8 changed files with 223 additions and 52 deletions

View File

@ -91,10 +91,30 @@ class Venta extends Service
* @return Model\Venta
* @throws Read
*/
public function getByUnidadId(int $unidad_id): Model\Venta
public function getActiveByUnidadId(int $unidad_id): Model\Venta
{
try {
return $this->process($this->ventaRepository->fetchByUnidadId($unidad_id));
return $this->process($this->ventaRepository->fetchActiveByUnidadId($unidad_id));
} catch (Implement\Exception\EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}
}
/**
* @param array $unidad_ids
* @return array
* @throws Read
*/
public function getActiveByUnidadIds(array $unidad_ids): array
{
try {
$ventas = $this->ventaRepository->fetchActiveByUnidadIds($unidad_ids);
return array_map(function($data) {
return [
'unidad_id' => $data['unidad_id'],
'venta' => $this->process($data['venta'])
];
}, $ventas);
} catch (Implement\Exception\EmptyResult $exception) {
throw new Read(__CLASS__, $exception);
}