Poder editar propietario de ventas, cambiando el propietario en si
This commit is contained in:
@ -302,4 +302,39 @@ class Ventas extends Controller
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function propietario(ServerRequestInterface $request, ResponseInterface $response,
|
||||
Service\Venta\Propietario $propietarioService,
|
||||
Repository\Venta $ventaRepository, int $venta_id): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$data = json_decode($body->getContents(), true);
|
||||
$this->logger->error(var_export($data, true));
|
||||
$output = [
|
||||
'input' => $data,
|
||||
'venta_id' => $venta_id,
|
||||
'propietario' => false,
|
||||
'edited' => false
|
||||
];
|
||||
try {
|
||||
$venta = $ventaRepository->fetchById($venta_id);
|
||||
$propietario = $propietarioService->getByRut($venta->propietario()->rut);
|
||||
$output['propietario'] = $propietario;
|
||||
if (isset($data['rut'])) {
|
||||
try {
|
||||
$propietario = $propietarioService->getByRut($data['rut']);
|
||||
$propietario = $propietarioService->edit($propietario, $data);
|
||||
} catch (EmptyResult) {
|
||||
$propietario = $propietarioService->addPropietario($data);
|
||||
}
|
||||
$data = [
|
||||
'propietario' => $propietario->rut
|
||||
];
|
||||
$ventaRepository->edit($venta, $data);
|
||||
} else {
|
||||
$propietario = $propietarioService->edit($propietario, $data);
|
||||
}
|
||||
$output['edited'] = true;
|
||||
} catch (EmptyResult) {}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user