FIX: API Proyecto Operadores

This commit is contained in:
Juan Pablo Vial
2022-01-24 17:58:20 -03:00
parent 4f7241e146
commit e672ac48a7
2 changed files with 8 additions and 9 deletions

View File

@ -47,9 +47,10 @@ class Proyectos {
$output = [ $output = [
'proyecto' => $proyecto->as_array(), 'proyecto' => $proyecto->as_array(),
'operadores' => $proyecto->operadores() ? array_map(function($item) { 'operadores' => $proyecto->operadores() ? array_map(function($item) {
if ($item) { $arr = $item->as_array();
return $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 }, $proyecto->operadores()) : null
]; ];
return $this->withJson($response, $output); return $this->withJson($response, $output);

View File

@ -45,12 +45,10 @@ class Proyecto extends Model {
public function operadores() { public function operadores() {
if ($this->operadores === null) { if ($this->operadores === null) {
$pas = $this->has_many(ProyectoAgente::class, 'proyecto')->find_many(); $pas = $this->has_many(ProyectoAgente::class, 'proyecto')->find_many();
$operadores = []; $pas = array_filter($pas, function($pa) {
foreach ($pas as $pa) { return ($pa->agente_tipo()->tipo() === 'operador');
$id = $pa->agente_tipo()->agente()->id; });
$operadores []= Model::factory(Operador::class)->find_one($id); $this->operadores = $pas;
}
$this->operadores = $operadores;
} }
return $this->operadores; return $this->operadores;
} }