Skip to content

Commit

Permalink
refactor: use services in import vcard (#5513)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Sep 18, 2021
1 parent 3883de7 commit c380928
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 187 deletions.
1 change: 1 addition & 0 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Contact extends Model
'last_consulted_at',
'created_at',
'first_met_additional_info',
'address_book_id',
];

/**
Expand Down
9 changes: 8 additions & 1 deletion app/Services/Contact/Contact/CreateContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use function Safe\json_encode;
use App\Models\Account\Account;
use App\Models\Contact\Contact;
use App\Models\Account\AddressBook;
use App\Jobs\AuditLog\LogAccountAudit;
use App\Models\Contact\ContactFieldType;
use App\Jobs\Avatars\GenerateDefaultAvatar;
Expand All @@ -28,6 +29,7 @@ public function rules()
return [
'account_id' => 'required|integer|exists:accounts,id',
'author_id' => 'required|integer|exists:users,id',
'address_book_id' => 'nullable|integer|exists:addressbooks,id',
'first_name' => 'required|string|max:255',
'middle_name' => 'nullable|string|max:255',
'last_name' => 'nullable|string|max:255',
Expand Down Expand Up @@ -69,6 +71,11 @@ public function execute(array $data): Contact
abort(402);
}

if (Arr::get($data, 'address_book_id')) {
AddressBook::where('account_id', $data['account_id'])
->findOrFail($data['address_book_id']);
}

// filter out the data that shall not be updated here
$dataOnly = Arr::except(
$data,
Expand Down Expand Up @@ -183,7 +190,7 @@ private function updateEmail(array $data, Contact $contact)
return;
}

$contactField = app(CreateContactField::class)->execute([
app(CreateContactField::class)->execute([
'account_id' => $data['account_id'],
'contact_id' => $contact->id,
'contact_field_type_id' => $contactFieldType->id,
Expand Down
Loading

0 comments on commit c380928

Please sign in to comment.