From e672ac48a7d65c58835449ed09bd30dc2da9f5e4 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 24 Jan 2022 17:58:20 -0300 Subject: [PATCH] FIX: API Proyecto Operadores --- api/common/Controller/Proyectos.php | 7 ++++--- api/src/Proyecto.php | 10 ++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/api/common/Controller/Proyectos.php b/api/common/Controller/Proyectos.php index 106e840..3d4ff13 100644 --- a/api/common/Controller/Proyectos.php +++ b/api/common/Controller/Proyectos.php @@ -47,9 +47,10 @@ class Proyectos { $output = [ 'proyecto' => $proyecto->as_array(), 'operadores' => $proyecto->operadores() ? array_map(function($item) { - if ($item) { - return $item->as_array(); - } + $arr = $item->as_array(); + $arr['agente_tipo'] = $item->agente_tipo()->as_array(); + $arr['agente_tipo']['agente'] = $arr['operador'] = $item->agente_tipo()->agente()->as_array(); + return $arr; }, $proyecto->operadores()) : null ]; return $this->withJson($response, $output); diff --git a/api/src/Proyecto.php b/api/src/Proyecto.php index dbf7d92..78be0a6 100644 --- a/api/src/Proyecto.php +++ b/api/src/Proyecto.php @@ -45,12 +45,10 @@ class Proyecto extends Model { public function operadores() { if ($this->operadores === null) { $pas = $this->has_many(ProyectoAgente::class, 'proyecto')->find_many(); - $operadores = []; - foreach ($pas as $pa) { - $id = $pa->agente_tipo()->agente()->id; - $operadores []= Model::factory(Operador::class)->find_one($id); - } - $this->operadores = $operadores; + $pas = array_filter($pas, function($pa) { + return ($pa->agente_tipo()->tipo() === 'operador'); + }); + $this->operadores = $pas; } return $this->operadores; }