This commit is contained in:
Juan Pablo Vial
2024-04-02 23:02:52 -03:00
parent 5d9ac2bc51
commit 8710c8a111
12 changed files with 457 additions and 0 deletions

View File

@ -55,4 +55,29 @@ class Inmobiliarias
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
public function agentes(ServerRequestInterface $request, ResponseInterface $response,
Repository\Inmobiliaria $inmobiliariaRepository,
Repository\Inmobiliaria\SociedadAgente $sociedadAgenteRepository,
Repository\Inmobiliaria\TipoAgente $tipoAgenteRepository,
int $inmobiliaria_rut): ResponseInterface
{
$input = $request->getParsedBody();
$output = [
'sociedad_rut' => $inmobiliaria_rut,
'input' => $input,
'sociedad' => null,
'agentes' => []
];
try {
$inmobiliaria = $inmobiliariaRepository->fetchById($inmobiliaria_rut);
$output['sociedad'] = $inmobiliaria;
if (isset($input['tipo_agente_id'])) {
$tipo = $tipoAgenteRepository->fetchById($input['tipo_agente_id']);
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedadAndTipo($inmobiliaria->rut, $tipo->id);
} else {
$output['agentes'] = $sociedadAgenteRepository->fetchBySociedad($inmobiliaria->rut);
}
} catch (EmptyResult) {}
return $this->withJson($response, $output);
}
}