mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
184 lines
6.2 KiB
PHP
184 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Accounts\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Accounts\Standards\Rules\CanCreateUser;
|
|
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
|
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
|
use App\Http\Resources\UserResource;
|
|
|
|
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompany;
|
|
use App\Classes\Modules\Companies\Services\CreatesCompany;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
|
|
|
use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact;
|
|
use App\Classes\Modules\Contacts\Services\CreatesContact;
|
|
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
|
|
|
use App\Classes\Modules\CompanyEmployees\Standards\Rules\CanCreateCompanyEmployee;
|
|
use App\Classes\Modules\CompanyEmployees\Services\CreatesCompanyEmployee;
|
|
use App\Classes\Modules\CompanyEmployees\DataTransferObjects\CompanyEmployeeObject;
|
|
|
|
use App\Classes\Modules\SegmentCompanies\Standards\Rules\CanCreateSegmentCompany;
|
|
use App\Classes\Modules\SegmentCompanies\Services\CreatesSegmentCompany;
|
|
use App\Classes\Modules\SegmentCompanies\DataTransferObjects\SegmentCompanyObject;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class CreateUserLogic extends AbstractControllerLogic
|
|
{
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Created User',
|
|
'message' => 'You have successfully created a new User'
|
|
];
|
|
}
|
|
|
|
/** @var CanCreateUser */
|
|
private $canCreateUser;
|
|
|
|
/** @var CreatesUser */
|
|
private $createsUser;
|
|
|
|
/** @var CanCreateCompany */
|
|
private $canCreateCompany;
|
|
|
|
/** @var CreatesCompany */
|
|
private $createsCompany;
|
|
|
|
/** @var CanCreateContact */
|
|
private $canCreateContact;
|
|
|
|
/** @var CreatesContact */
|
|
private $createsContact;
|
|
|
|
/** @var CanCreateCompanyEmployee */
|
|
private $canCreateCompanyEmployee;
|
|
|
|
/** @var CreatesCompanyEmployee */
|
|
private $createsCompanyEmployee;
|
|
|
|
/** @var CanCreateSegmentCompany */
|
|
private $canCreateSegmentCompany;
|
|
|
|
/** @var CreatesSegmentCompany */
|
|
private $createsSegmentCompany;
|
|
|
|
|
|
/**
|
|
* CreateUserLogic constructor.
|
|
* @param CanCreateUser $canCreateUser
|
|
* @param CreatesUser $createsUser
|
|
* @param CanCreateCompany $canCreateCompany
|
|
* @param CreatesCompany $createsCompany
|
|
* @param CanCreateContact $canCreateContact
|
|
* @param CreatesContact $createsContact
|
|
* @param CanCreateCompanyEmployee $canCreateCompanyEmployee
|
|
* @param CreatesCompanyEmployee $createsCompanyEmployee
|
|
* @param CanCreateSegmentCompany $canCreateSegmentCompany
|
|
* @param CreatesSegmentCompany $createsSegmentCompany
|
|
*/
|
|
public function __construct(
|
|
CanCreateUser $canCreateUser,
|
|
CreatesUser $createsUser,
|
|
CanCreateCompany $canCreateCompany,
|
|
CreatesCompany $createsCompany,
|
|
CanCreateContact $canCreateContact,
|
|
CreatesContact $createsContact,
|
|
CanCreateCompanyEmployee $canCreateCompanyEmployee,
|
|
CreatesCompanyEmployee $createsCompanyEmployee,
|
|
CanCreateSegmentCompany $canCreateSegmentCompany,
|
|
CreatesSegmentCompany $createsSegmentCompany
|
|
)
|
|
{
|
|
$this->canCreateUser = $canCreateUser;
|
|
$this->createsUser = $createsUser;
|
|
$this->canCreateCompany = $canCreateCompany;
|
|
$this->createsCompany = $createsCompany;
|
|
$this->canCreateContact = $canCreateContact;
|
|
$this->createsContact = $createsContact;
|
|
$this->canCreateCompanyEmployee = $canCreateCompanyEmployee;
|
|
$this->createsCompanyEmployee = $createsCompanyEmployee;
|
|
$this->canCreateSegmentCompany = $canCreateSegmentCompany;
|
|
$this->createsSegmentCompany = $createsSegmentCompany;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$user_object = new UserObject(
|
|
$request->input('name'),
|
|
$request->input('email'),
|
|
$request->input('password'),
|
|
$request->input('password_confirmation'),
|
|
2,
|
|
9
|
|
);
|
|
|
|
$this->canCreateUser->passes($user_object);
|
|
$user_query = $this->createsUser->execute($user_object);
|
|
|
|
$company_object = new CompanyObject(
|
|
$request->input('company_name'),
|
|
$request->input('company_reference'),
|
|
null
|
|
);
|
|
|
|
$this->canCreateCompany->passes($company_object);
|
|
$company_query = $this->createsCompany->execute($company_object);
|
|
|
|
$contact_object = new ContactObject(
|
|
1,
|
|
$company_query->id,
|
|
$request->input('contact_reference'),
|
|
$request->input('phone'),
|
|
$request->input('contact_email'),
|
|
$request->input('wechat_id')
|
|
);
|
|
|
|
$this->canCreateContact->passes($contact_object);
|
|
$contact_query = $this->createsContact->execute($contact_object);
|
|
|
|
$company_employee_object = new CompanyEmployeeObject(
|
|
$company_query->id,
|
|
$user_query->id
|
|
);
|
|
|
|
$this->canCreateCompanyEmployee->passes($company_employee_object);
|
|
$company_employee_query = $this->createsCompanyEmployee->execute($user_query, $company_employee_object);
|
|
|
|
|
|
$segment_company_object = new SegmentCompanyObject(
|
|
1,
|
|
$company_query->id
|
|
);
|
|
|
|
$this->canCreateSegmentCompany->passes($segment_company_object);
|
|
$segment_company_query = $this->createsSegmentCompany->execute($company_query, $segment_company_object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new UserResource($user_query));
|
|
|
|
} catch (\Exception $exception) {
|
|
dd($exception);
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
|
|
}
|
|
} |