FIX: Editar datos Broker
This commit is contained in:
@ -168,7 +168,20 @@
|
|||||||
window.location.reload()
|
window.location.reload()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
edit: (broker_rut, data) => {},
|
edit: data => {
|
||||||
|
const url = '{{$urls->api}}/proyectos/brokers/edit'
|
||||||
|
const method = 'post'
|
||||||
|
const body = new FormData()
|
||||||
|
body.append('brokers[]', JSON.stringify(data))
|
||||||
|
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||||
|
if (!json.success) {
|
||||||
|
console.error(json.errors)
|
||||||
|
alert('No se pudo editar operador.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
window.location.reload()
|
||||||
|
})
|
||||||
|
},
|
||||||
delete: broker_rut => {
|
delete: broker_rut => {
|
||||||
const url = '{{$urls->api}}/proyectos/broker/' + broker_rut
|
const url = '{{$urls->api}}/proyectos/broker/' + broker_rut
|
||||||
const method = 'delete'
|
const method = 'delete'
|
||||||
|
@ -76,12 +76,14 @@
|
|||||||
const form = document.getElementById(this.ids.form)
|
const form = document.getElementById(this.ids.form)
|
||||||
const broker_rut = form.querySelector('[name="broker_rut"]').value
|
const broker_rut = form.querySelector('[name="broker_rut"]').value
|
||||||
const data = {
|
const data = {
|
||||||
|
rut: form.querySelector('[name="rut"]').value.replace(/\D/g, ''),
|
||||||
name: form.querySelector('[name="name"]').value,
|
name: form.querySelector('[name="name"]').value,
|
||||||
|
contact: form.querySelector('[name="contact"]').value || '',
|
||||||
legal_name: form.querySelector('[name="legal_name"]').value,
|
legal_name: form.querySelector('[name="legal_name"]').value,
|
||||||
email: form.querySelector('[name="email"]').value || '',
|
email: form.querySelector('[name="email"]').value || '',
|
||||||
phone: form.querySelector('[name="phone"]').value || ''
|
phone: form.querySelector('[name="phone"]').value || ''
|
||||||
}
|
}
|
||||||
this.handler.execute().edit(broker_rut, data)
|
this.handler.execute().edit(data)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.modal.modal('hide')
|
this.modal.modal('hide')
|
||||||
|
@ -70,9 +70,10 @@ class Brokers
|
|||||||
];
|
];
|
||||||
foreach ($body['brokers'] as $data) {
|
foreach ($body['brokers'] as $data) {
|
||||||
try {
|
try {
|
||||||
|
$data = json_decode($data, true);
|
||||||
$output['brokers'] []= [
|
$output['brokers'] []= [
|
||||||
'rut' => $data['rut'],
|
'rut' => $data['rut'],
|
||||||
'broker' => $brokerService->edit(json_decode($data, true)),
|
'broker' => $brokerService->edit($data),
|
||||||
'success' => true
|
'success' => true
|
||||||
];
|
];
|
||||||
$output['partial'] = true;
|
$output['partial'] = true;
|
||||||
|
@ -76,7 +76,7 @@ class Broker extends Ideal\Service
|
|||||||
public function edit(array $data): Model\Proyecto\Broker
|
public function edit(array $data): Model\Proyecto\Broker
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$broker = $this->brokerRepository->fetchById($data['id']);
|
$broker = $this->brokerRepository->fetchById($data['rut']);
|
||||||
} catch (EmptyResult $exception) {
|
} catch (EmptyResult $exception) {
|
||||||
throw new ServiceAction\Update(__CLASS__, $exception);
|
throw new ServiceAction\Update(__CLASS__, $exception);
|
||||||
}
|
}
|
||||||
@ -180,6 +180,23 @@ class Broker extends Ideal\Service
|
|||||||
} catch (EmptyResult $exception) {
|
} catch (EmptyResult $exception) {
|
||||||
throw new ServiceAction\Update(__CLASS__, $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 {
|
try {
|
||||||
$data['broker_rut'] = $broker->rut;
|
$data['broker_rut'] = $broker->rut;
|
||||||
$filteredData = $this->dataRepository->filterData($data);
|
$filteredData = $this->dataRepository->filterData($data);
|
||||||
|
Reference in New Issue
Block a user