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

@ -9,7 +9,7 @@ class Data extends Common\Ideal\Repository
{
public function __construct(Common\Define\Connection $connection,
protected Repository\Proyecto\Broker $brokerRepository,
protected Repository\Persona $personaRepository)
protected Repository\Proyecto\Broker\Contact $contactRepository)
{
parent::__construct($connection);
}
@ -27,13 +27,13 @@ class Data extends Common\Ideal\Repository
->setFunction(function($data) {
return $this->brokerRepository->fetchById($data['broker_rut']);
}))
->register('representative_rut', (new Common\Implement\Repository\Mapper())
->register('representative_id', (new Common\Implement\Repository\Mapper())
->setProperty('representative')
->setDefault(null)
->setFunction(function($data) {
if ($data['representative_rut'] == null) return null;
if ($data['representative_id'] === null) return null;
try {
return $this->personaRepository->fetchById($data['representative_rut']);
return $this->contactRepository->fetchById($data['representative_id']);
} catch (Common\Implement\Exception\EmptyResult) {
return null;
}
@ -46,8 +46,8 @@ class Data extends Common\Ideal\Repository
public function save(Common\Define\Model $model): Model\Proyecto\Broker\Data
{
$model->id = $this->saveNew(
['broker_rut', 'representative_rut', 'legal_name'],
[$model->broker->rut, $model->representative?->rut, $model->legalName]);
['broker_rut', 'representative_id', 'legal_name'],
[$model->broker->rut, $model->representative?->id, $model->legalName]);
return $model;
}
@ -59,7 +59,7 @@ class Data extends Common\Ideal\Repository
*/
public function edit(Common\Define\Model $model, array $new_data): Model\Proyecto\Broker\Data
{
return $this->update($model, ['representative_rut', 'legal_name'], $new_data);
return $this->update($model, ['representative_id', 'legal_name'], $new_data);
}
/**