From 8dc45d0848a75cbd37956a4eeb71e10bc8c71415 Mon Sep 17 00:00:00 2001 From: weichien00 Date: Thu, 8 Jul 2021 01:58:32 +0800 Subject: [PATCH] update: changes on Company Module based on changes #6 --- .../DataTransferObjects/CompanyObject.php | 21 ++++-------- .../DataTransferObjects/EmploymentObject.php | 34 +++++++++++++------ .../Processors/CreateCompanyProcessor.php | 6 ++-- .../Companies/Services/AssignsEmployee.php | 4 +-- .../Companies/Services/CreatesCompany.php | 2 +- .../Validators/CompanyEmployeeValidation.php | 2 +- .../Validators/CompanyValidation.php | 1 - 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php index 09b0e153..3bd52d5c 100644 --- a/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php +++ b/app/Classes/Modules/Companies/DataTransferObjects/CompanyObject.php @@ -14,9 +14,6 @@ class CompanyObject implements DataTransferObject /** @var string */ private $reference; - /** @var int|null */ - private $businessType; - /** @var int|null */ private $type; @@ -27,15 +24,17 @@ class CompanyObject implements DataTransferObject * CompanyObject constructor. * @param string $name * @param string $reference - * @param int|null $businessType * @param int|null $type * @param int|null $status */ - public function __construct(string $name, string $reference, ?int $businessType = BusinessType::IMPORTER, ?int $type = BusinessType::IMPORTER, ?int $status = ApprovalStatus::PENDING_SUBMISSION) - { + public function __construct( + string $name, + string $reference, + ?int $type = BusinessType::IMPORTER, + ?int $status = ApprovalStatus::PENDING_SUBMISSION + ) { $this->name = $name; $this->reference = $reference; - $this->businessType = $businessType; $this->type = $type; $this->status = $status; } @@ -56,14 +55,6 @@ class CompanyObject implements DataTransferObject return $this->reference; } - /** - * @return int - */ - public function getBusinessType(): int - { - return $this->businessType; - } - /** * @return int */ diff --git a/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php b/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php index 8a6781a0..8a6ac0fe 100644 --- a/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php +++ b/app/Classes/Modules/Companies/DataTransferObjects/EmploymentObject.php @@ -4,13 +4,13 @@ namespace App\Classes\Modules\Companies\DataTransferObjects; use App\Classes\General\Interfaces\DataTransferObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Models\Company; +use App\Models\CompanyModule; use App\Models\User; class EmploymentObject implements DataTransferObject -{ - /** @var Company */ - private $company; +{ + /** @var CompanyModule */ + private $companyModule; /** @var User */ private $user; @@ -18,25 +18,30 @@ class EmploymentObject implements DataTransferObject /** @var int|null */ private $status; + /** @var int|null */ + private $roleId; + /** * EmploymentObject constructor. - * @param Company $company + * @param CompanyModule $companyModule * @param User $user * @param int|null $status + * @param int|null $roleId */ - public function __construct(Company $company, User $user, ?int $status = ApprovalStatus::APPROVED) + public function __construct(CompanyModule $companyModule, User $user, ?int $status = ApprovalStatus::APPROVED, ?int $roleId = 1) { - $this->company = $company; + $this->companyModule = $companyModule; $this->user = $user; + $this->roleId = $roleId; $this->status = $status; } /** - * @return Company + * @return CompanyModule */ - public function getCompany(): Company + public function getCompanyModule(): CompanyModule { - return $this->company; + return $this->companyModule; } /** @@ -55,4 +60,11 @@ class EmploymentObject implements DataTransferObject return $this->status; } -} \ No newline at end of file + /** + * @return int + */ + public function getRoleId(): int + { + return $this->roleId; + } +} diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php index fc84e9cc..95ef5eb9 100644 --- a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php @@ -43,13 +43,15 @@ class CreateCompanyProcessor * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ - public function execute(Request $request, int $businessType = BusinessType::IMPORTER, ?int $companyType = CompanyType::COMPANY_BUSINESS, ?int $status = ApprovalStatus::PENDING_SUBMISSION): Model { + public function execute(Request $request, ?int $companyType = CompanyType::COMPANY_BUSINESS, ?int $status = ApprovalStatus::PENDING_SUBMISSION): Model { $companyName = $companyType === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name'); $company_object = new CompanyObject( $companyName, mt_rand(1000, 9999).(new GeneratesInitials())->name($companyName)->length(3)->generate(), - $businessType, $companyType, $status); + $companyType, + $status); + $this->canCreateCompany->passes($company_object); diff --git a/app/Classes/Modules/Companies/Services/AssignsEmployee.php b/app/Classes/Modules/Companies/Services/AssignsEmployee.php index 0e5b8636..abf89c42 100644 --- a/app/Classes/Modules/Companies/Services/AssignsEmployee.php +++ b/app/Classes/Modules/Companies/Services/AssignsEmployee.php @@ -18,9 +18,9 @@ class AssignsEmployee extends AbstractUpdateRecord { try { - $object->getCompany()->employees()->attach($object->getUser(), ['status' => $object->getStatus()]); + $object->getCompanyModule()->employees()->attach($object->getUser(), ['status' => $object->getStatus(),'role_id' => $object->getRoleId()]); - return $object->getCompany(); + return $object->getCompanyModule(); } catch (QueryException $exception){ throw new MalformedRequestException($exception); diff --git a/app/Classes/Modules/Companies/Services/CreatesCompany.php b/app/Classes/Modules/Companies/Services/CreatesCompany.php index a6f71632..f1babd82 100644 --- a/app/Classes/Modules/Companies/Services/CreatesCompany.php +++ b/app/Classes/Modules/Companies/Services/CreatesCompany.php @@ -20,7 +20,7 @@ class CreatesCompany extends AbstractUpdateRecord $model->name = $object->getName(); $model->reference = $object->getReference(); $model->type = $object->getType(); - $model->business_type = $object->getBusinessType(); + $model->status = $object->getStatus(); return $this->handler($model); } diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php index f396ac41..49ff7629 100644 --- a/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyEmployeeValidation.php @@ -14,7 +14,7 @@ class CompanyEmployeeValidation extends AbstractValidation protected function data($object): array { return [ - 'company_id' => $object->getCompany()->id, + 'company_id' => $object->getCompanyModule()->id, 'user_id' => $object->getUser()->id, ]; } diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php index 173dc0bd..5ea263ac 100644 --- a/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyValidation.php @@ -16,7 +16,6 @@ class CompanyValidation extends AbstractValidation return [ 'company_name' => $object->getName(), 'company_reference' => $object->getReference(), - 'type' => $object->getBusinessType() ]; }