Correct exceptions

This commit is contained in:
Juan Pablo Vial
2025-10-17 12:26:46 -03:00
parent 06558d778d
commit 71309e13a0
2 changed files with 9 additions and 2 deletions

View File

@ -4,8 +4,11 @@ namespace Incoviba\Controller\API\Ventas;
use DateTimeImmutable; use DateTimeImmutable;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
use Incoviba\Controller\API\withJson; use Incoviba\Controller\API\withJson;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Incoviba\Repository; use Incoviba\Repository;
use Incoviba\Service; use Incoviba\Service;
@ -42,7 +45,7 @@ class Escrituras
try { try {
$escrituraService->edit($venta_id, $body); $escrituraService->edit($venta_id, $body);
$output['success'] = true; $output['success'] = true;
} catch (EmptyResult) {} } catch (Read|Update|EmptyResult) {}
return $this->withJson($response, $output); return $this->withJson($response, $output);
} }
} }

View File

@ -4,6 +4,8 @@ namespace Incoviba\Service\Venta;
use Exception; use Exception;
use DateTimeImmutable; use DateTimeImmutable;
use DateMalformedStringException; use DateMalformedStringException;
use Incoviba\Exception\ServiceAction\Read;
use Incoviba\Exception\ServiceAction\Update;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Incoviba\Common\Ideal; use Incoviba\Common\Ideal;
use Incoviba\Common\Implement\Exception\EmptyResult; use Incoviba\Common\Implement\Exception\EmptyResult;
@ -56,13 +58,15 @@ class Escritura extends Ideal\Service
/** /**
* @throws EmptyResult * @throws EmptyResult
* @throws Read
* @throws Update
*/ */
public function edit(int $venta_id, array $data): Model\Venta\Escritura public function edit(int $venta_id, array $data): Model\Venta\Escritura
{ {
$venta = $this->ventaService->getById($venta_id); $venta = $this->ventaService->getById($venta_id);
$estado = $venta->currentEstado(); $estado = $venta->currentEstado();
if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) { if (!in_array($estado->tipoEstadoVenta->descripcion, ['escriturando', 'firmado por inmobiliaria'])) {
throw new EmptyResult(''); throw new Update(__CLASS__);
} }
try { try {
$data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d'); $data['fecha'] = (new DateTimeImmutable($data['fecha']))->format('Y-m-d');