mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-28 00:44:23 +00:00
update: changes on Company Module based on changes #6
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getRoleId(): int
|
||||
{
|
||||
return $this->roleId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ class CompanyValidation extends AbstractValidation
|
||||
return [
|
||||
'company_name' => $object->getName(),
|
||||
'company_reference' => $object->getReference(),
|
||||
'type' => $object->getBusinessType()
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user