FIX: Editar datos Broker
This commit is contained in:
@ -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;
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user