mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-19 12:34:01 +00:00
151 lines
6.7 KiB
PHP
151 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Delivery\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\General\Services\GeneratesInitials;
|
|
use App\Classes\Modules\Accounts\Processors\AuthenticationProcessor;
|
|
use App\Classes\Modules\Accounts\Processors\CreateUserProcessor;
|
|
use App\Classes\Modules\Accounts\Processors\GenerateEmailVerificationAttemptProcessor;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\CompanyConnectionObject;
|
|
use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
|
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
|
|
use App\Classes\Modules\Companies\Processors\CreateCompanyModuleProcessor;
|
|
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
|
use App\Classes\Modules\Companies\Services\ApprovesCompanyConnection;
|
|
use App\Classes\Modules\Companies\Services\CreatesCompanyConnection;
|
|
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
|
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
|
use App\Classes\Modules\Documents\Processors\UploadIdentityDocumentProcessor;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\BusinessType;
|
|
use App\Classes\ValueObjects\Constants\CompanyType;
|
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\CompanyModule;
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class CreateDeliveryCustomerLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification(): array
|
|
{
|
|
return [
|
|
'title' => 'Created User',
|
|
'message' => 'You have successfully created a new User'
|
|
];
|
|
}
|
|
|
|
/** @var CreateUserProcessor */
|
|
private $createUserProcessor;
|
|
|
|
/** @var CreateCompanyProcessor */
|
|
private $createCompanyProcessor;
|
|
|
|
/** @var CreateCompanyModuleProcessor */
|
|
private $createCompanyModuleProcessor;
|
|
|
|
/** @var CreateContactProcessor */
|
|
private $createContactProcessor;
|
|
|
|
/** @var CreatesCompanyConnection */
|
|
private $createsCompanyConnection;
|
|
|
|
/** @var ApprovesCompanyConnection */
|
|
private $approvesCompanyConnection;
|
|
|
|
/** @var AssignEmployeeProcessor */
|
|
private $assignEmployeeProcessor;
|
|
|
|
/** @var UploadIdentityDocumentProcessor */
|
|
private $uploadIdentityDocumentProcessor;
|
|
|
|
/** @var AuthenticationProcessor */
|
|
private $authenticationProcessor;
|
|
|
|
/** @var GenerateEmailVerificationAttemptProcessor */
|
|
private $generateEmailVerificationAttemptProcessor;
|
|
|
|
/** @var FetchesCompanyModule */
|
|
private $fetchesCompanyModule;
|
|
|
|
/**
|
|
* CreateDeliveryCustomerLogic constructor.
|
|
* @param CreateUserProcessor $createUserProcessor
|
|
* @param CreateCompanyProcessor $createCompanyProcessor
|
|
* @param CreateCompanyModuleProcessor $createCompanyModuleProcessor
|
|
* @param CreateContactProcessor $createContactProcessor
|
|
* @param CreatesCompanyConnection $createsCompanyConnection
|
|
* @param ApprovesCompanyConnection $approvesCompanyConnection
|
|
* @param AssignEmployeeProcessor $assignEmployeeProcessor
|
|
* @param UploadIdentityDocumentProcessor $uploadIdentityDocumentProcessor
|
|
* @param AuthenticationProcessor $authenticationProcessor
|
|
* @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
|
|
* @param FetchesCompanyModule $fetchesCompanyModule
|
|
*/
|
|
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, AssignEmployeeProcessor $assignEmployeeProcessor, UploadIdentityDocumentProcessor $uploadIdentityDocumentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor, FetchesCompanyModule $fetchesCompanyModule)
|
|
{
|
|
$this->createUserProcessor = $createUserProcessor;
|
|
$this->createCompanyProcessor = $createCompanyProcessor;
|
|
$this->createCompanyModuleProcessor = $createCompanyModuleProcessor;
|
|
$this->createContactProcessor = $createContactProcessor;
|
|
$this->createsCompanyConnection = $createsCompanyConnection;
|
|
$this->approvesCompanyConnection = $approvesCompanyConnection;
|
|
$this->assignEmployeeProcessor = $assignEmployeeProcessor;
|
|
$this->uploadIdentityDocumentProcessor = $uploadIdentityDocumentProcessor;
|
|
$this->authenticationProcessor = $authenticationProcessor;
|
|
$this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
|
|
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
|
* @throws \App\Classes\Exceptions\AccessUnauthorisedException
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
* @throws \App\Classes\Exceptions\RequestValidationException
|
|
*/
|
|
public function logic(Request $request): JsonResponse
|
|
{
|
|
/** @var User $user */
|
|
$user = $this->createUserProcessor->execute($request, RoleTypes::USER, !App::environment(['production']) ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION);
|
|
|
|
/** @var Company $company */
|
|
$company = $this->createCompanyProcessor->execute($request->input('name'), CompanyType::PERSONAL_BUSINESS, ApprovalStatus::PENDING_SUBMISSION);
|
|
|
|
$contactObject = new ContactObject($request->input('name'), $request->input('phone'), $request->input('contact_email'), $request->input('wechat_id'));
|
|
|
|
$this->createContactProcessor->execute($contactObject, $company);
|
|
|
|
/** @var CompanyModule $companyModule */
|
|
$companyModule = $this->createCompanyModuleProcessor->execute($company, BusinessType::ONLINE_SELLER);
|
|
|
|
$inviter = $this->fetchesCompanyModule->execute(['reference'=>'HWT']);
|
|
|
|
$connectionObject = new CompanyConnectionObject($companyModule, $inviter, mt_rand(1000, 9999).(new GeneratesInitials())->name($company->name)->length(3)->generate(), 'LMD');
|
|
|
|
$connection = $this->createsCompanyConnection->execute($connectionObject);
|
|
|
|
$this->approvesCompanyConnection->execute($connection);
|
|
|
|
$Object = new EmploymentObject($companyModule, $user);
|
|
|
|
$this->assignEmployeeProcessor->execute($Object);
|
|
|
|
return $this->response($this->authenticationProcessor->execute($request));
|
|
}
|
|
}
|