This commit is contained in:
42
api/app/Services/Cadastro/SujeitoAtencao/ObitoService.php
Normal file
42
api/app/Services/Cadastro/SujeitoAtencao/ObitoService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Cadastro\SujeitoAtencao;
|
||||
|
||||
use App\Exceptions\Cadastro\SujeitoAtencao\ObitoAlreadyRegisteredException;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Cidadao;
|
||||
use App\Services\Integracao\IntegracaoCidadaoService;
|
||||
|
||||
class ObitoService
|
||||
{
|
||||
private Cidadao $cidadao;
|
||||
|
||||
public function __construct(Cidadao $cidadao)
|
||||
{
|
||||
$this->cidadao = $cidadao;
|
||||
}
|
||||
|
||||
public function save(\DateTime $obitoEm, $declaracao, string $causa, int $cidId = null, $usuarioId = null)
|
||||
{
|
||||
if ($this->cidadao->obito) {
|
||||
|
||||
throw new ObitoAlreadyRegisteredException();
|
||||
}
|
||||
|
||||
$obito = $this->cidadao->obito()->create([
|
||||
'usuario_id' => $usuarioId ?? null,
|
||||
'obito_em' => $obitoEm,
|
||||
'declaracao' => $declaracao,
|
||||
'causa' => $causa,
|
||||
'cid_id' => $cidId,
|
||||
]);
|
||||
|
||||
IntegracaoCidadaoService::integrar($this->cidadao->id);
|
||||
|
||||
return $obito;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->cidadao->obito;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user