From bfda0d85968995d10f3c20be61dae10439a7eb69 Mon Sep 17 00:00:00 2001 From: hazim Date: Thu, 7 Mar 2019 16:33:28 +0800 Subject: [PATCH] update contact recode and clean up --- .../Contacts/Services/CreatesContact.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Classes/Modules/Contacts/Services/CreatesContact.php b/app/Classes/Modules/Contacts/Services/CreatesContact.php index 30596d3..95aaab4 100644 --- a/app/Classes/Modules/Contacts/Services/CreatesContact.php +++ b/app/Classes/Modules/Contacts/Services/CreatesContact.php @@ -3,6 +3,7 @@ namespace App\Classes\Modules\Contacts\Services; +use App\Classes\Modules\Contacts\Exceptions\CannotCreateContactException; use App\Models\Contact; use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject; @@ -28,16 +29,22 @@ class CreatesContact */ public function execute(ContactObject $contact, int $type, int $referenceId) { - $this->repository->type = $type; - $this->repository->reference_id = $referenceId; - $this->repository->name = $contact->getName(); - $this->repository->designation = $contact->getDesignation(); - $this->repository->email = $contact->getEmail(); - $this->repository->contact = $contact->getContact(); + try{ - $this->repository->save(); + $this->repository->type = $type; + $this->repository->reference_id = $Id; + $this->repository->name = $contact->getName(); + $this->repository->designation = $contact->getDesignation(); + $this->repository->email = $contact->getEmail(); + $this->repository->contact = $contact->getContact(); + $this->repository->save(); + return $this->repository; + } + catch (\Exception $exception) + { + throw new CannotCreateContactException($exception->getMessage()); + } - return $this->repository; } } \ No newline at end of file