-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: companies tab (monicahq/chandler#350)
- Loading branch information
Showing
26 changed files
with
524 additions
and
4 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
app/Domains/Contact/ManageJobInformation/Services/ResetJobInformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace App\Domains\Contact\ManageJobInformation\Services; | ||
|
||
use App\Interfaces\ServiceInterface; | ||
use App\Models\Contact; | ||
use App\Models\ContactFeedItem; | ||
use App\Services\BaseService; | ||
use Carbon\Carbon; | ||
|
||
class ResetJobInformation extends BaseService implements ServiceInterface | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'account_id' => 'required|integer|exists:accounts,id', | ||
'vault_id' => 'required|integer|exists:vaults,id', | ||
'author_id' => 'required|integer|exists:users,id', | ||
'contact_id' => 'required|integer|exists:contacts,id', | ||
]; | ||
} | ||
|
||
/** | ||
* Get the permissions that apply to the user calling the service. | ||
* | ||
* @return array | ||
*/ | ||
public function permissions(): array | ||
{ | ||
return [ | ||
'author_must_belong_to_account', | ||
'vault_must_belong_to_account', | ||
'author_must_be_vault_editor', | ||
'contact_must_belong_to_vault', | ||
]; | ||
} | ||
|
||
/** | ||
* Reset job information for the given contact. | ||
* | ||
* @param array $data | ||
* @return Contact | ||
*/ | ||
public function execute(array $data): Contact | ||
{ | ||
$this->validateRules($data); | ||
|
||
$this->contact->company_id = null; | ||
$this->contact->job_position = null; | ||
$this->contact->save(); | ||
|
||
$this->updateLastEditedDate(); | ||
|
||
ContactFeedItem::create([ | ||
'author_id' => $this->author->id, | ||
'contact_id' => $this->contact->id, | ||
'action' => ContactFeedItem::ACTION_JOB_INFORMATION_UPDATED, | ||
]); | ||
|
||
return $this->contact; | ||
} | ||
|
||
private function updateLastEditedDate(): void | ||
{ | ||
$this->contact->last_updated_at = Carbon::now(); | ||
$this->contact->save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/Domains/Vault/ManageCompanies/Web/Controllers/VaultCompanyController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Domains\Vault\ManageCompanies\Web\Controllers; | ||
|
||
use App\Domains\Vault\ManageCompanies\Web\ViewHelpers\CompanyIndexViewHelper; | ||
use App\Domains\Vault\ManageVault\Web\ViewHelpers\VaultIndexViewHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Vault; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
|
||
class VaultCompanyController extends Controller | ||
{ | ||
public function index(Request $request, int $vaultId) | ||
{ | ||
$vault = Vault::findOrFail($vaultId); | ||
|
||
return Inertia::render('Vault/Companies/Index', [ | ||
'layoutData' => VaultIndexViewHelper::layoutData($vault), | ||
'data' => CompanyIndexViewHelper::data($vault), | ||
]); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/Domains/Vault/ManageCompanies/Web/ViewHelpers/CompanyIndexViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Domains\Vault\ManageCompanies\Web\ViewHelpers; | ||
|
||
use App\Models\Company; | ||
use App\Models\Contact; | ||
use App\Models\Vault; | ||
|
||
class CompanyIndexViewHelper | ||
{ | ||
public static function data(Vault $vault): array | ||
{ | ||
$collection = $vault->companies()->orderBy('name', 'asc') | ||
->with('contacts') | ||
->get() | ||
->map(function ($company) use ($vault) { | ||
return self::dto($vault, $company); | ||
}); | ||
|
||
return [ | ||
'companies' => $collection, | ||
]; | ||
} | ||
|
||
public static function dto(Vault $vault, Company $company): array | ||
{ | ||
return [ | ||
'id' => $company->id, | ||
'name' => $company->name, | ||
'contacts' => $company->contacts() | ||
->get() | ||
->map(fn (Contact $contact) => [ | ||
'id' => $contact->id, | ||
'avatar' => $contact->avatar, | ||
'url' => [ | ||
'show' => route('contact.show', [ | ||
'vault' => $contact->vault_id, | ||
'contact' => $contact->id, | ||
]), | ||
], | ||
]), | ||
'url' => [ | ||
'show' => route('vault.companies.show', [ | ||
'vault' => $vault->id, | ||
'company' => $company->id, | ||
]), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.