Broker Contact

This commit is contained in:
Juan Pablo Vial
2025-03-07 17:11:59 -03:00
parent 2bc30ab9e8
commit 5055d2703c
12 changed files with 452 additions and 124 deletions

View File

@ -15,7 +15,9 @@ class Broker extends Ideal\Service
{
public function __construct(LoggerInterface $logger,
protected Repository\Proyecto\Broker $brokerRepository,
protected Repository\Proyecto\Broker\Data $dataRepository, protected Service\Persona $personaService)
protected Repository\Proyecto\Broker\Data $dataRepository,
protected Repository\Proyecto\Broker\Contact $contactRepository,
protected Repository\Proyecto\Broker\Contract $contractRepository)
{
parent::__construct($logger);
}
@ -110,9 +112,11 @@ class Broker extends Ideal\Service
protected function process(Model\Proyecto\Broker $broker): Model\Proyecto\Broker
{
$broker->addFactory('data', (new Factory())
->setArgs(['broker_rut' => $broker->rut])
->setCallable([$this->dataRepository, 'fetchByBroker'])
);
->setArgs(['broker_rut' => $broker->rut])
->setCallable([$this->dataRepository, 'fetchByBroker']))
->addFactory('contracts', (new Factory())
->setArgs(['brokerRut' => $broker->rut])
->setCallable([$this->contractRepository, 'fetchByBroker']));
return $broker;
}
@ -127,11 +131,27 @@ class Broker extends Ideal\Service
{
$data['broker_rut'] = $broker->rut;
$filteredData = $this->dataRepository->filterData($data);
if (isset($filteredData['representative_rut'])) {
if (isset($data['contact'])) {
try {
$this->personaService->getById($filteredData['representative_rut']);
} catch (ServiceAction\Read) {
unset($filteredData['representative_rut']);
$representative = $this->contactRepository->fetchByName($data['contact']);
$filteredData['representative_id'] = $representative->id;
} catch (EmptyResult) {
$representativeData = $this->contactRepository->filterData($data);
$representativeData['name'] = $data['contact'];
$representative = $this->contactRepository->create($representativeData);
try {
$representative = $this->contactRepository->save($representative);
$filteredData['representative_id'] = $representative->id;
} catch (PDOException) {
unset($representative);
}
}
}
if (isset($filteredData['representative_id'])) {
try {
$this->contactRepository->fetchById($filteredData['representative_id']);
} catch (EmptyResult) {
unset($filteredData['representative_id']);
}
}
try {