FIX: Editar datos Broker

This commit is contained in:
Juan Pablo Vial
2025-03-12 18:31:21 -03:00
parent 7c7c8315e2
commit 8b04eb262f
4 changed files with 37 additions and 4 deletions

View File

@ -70,9 +70,10 @@ class Brokers
];
foreach ($body['brokers'] as $data) {
try {
$data = json_decode($data, true);
$output['brokers'] []= [
'rut' => $data['rut'],
'broker' => $brokerService->edit(json_decode($data, true)),
'broker' => $brokerService->edit($data),
'success' => true
];
$output['partial'] = true;

View File

@ -76,7 +76,7 @@ class Broker extends Ideal\Service
public function edit(array $data): Model\Proyecto\Broker
{
try {
$broker = $this->brokerRepository->fetchById($data['id']);
$broker = $this->brokerRepository->fetchById($data['rut']);
} catch (EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
@ -180,6 +180,23 @@ class Broker extends Ideal\Service
} catch (EmptyResult $exception) {
throw new ServiceAction\Update(__CLASS__, $exception);
}
if (isset($data['contact'])) {
try {
$representative = $this->contactRepository->fetchByName($data['contact']);
$data['representative_id'] = $representative->id;
} catch (EmptyResult) {
$representativeData = $this->contactRepository->filterData($data);
$representativeData['name'] = $data['contact'];
try {
$representative = $this->contactRepository->create($representativeData);
$representative = $this->contactRepository->save($representative);
$data['representative_id'] = $representative->id;
} catch (PDOException) {
unset($representative);
unset($data['contact']);
}
}
}
try {
$data['broker_rut'] = $broker->rut;
$filteredData = $this->dataRepository->filterData($data);