diff --git a/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php new file mode 100644 index 00000000..866af157 --- /dev/null +++ b/app/Classes/Modules/Accounts/ControllersLogic/CreateCustomerLogic.php @@ -0,0 +1,108 @@ + 'Created User', + 'message' => 'You have successfully created a new User' + ]; + } + + /** @var CreateUserProcessor */ + private $createUserProcessor; + + /** @var CreateCompanyProcessor */ + private $createCompanyProcessor; + + /** @var CreateContactProcessor */ + private $createContactProcessor; + + /** @var AssignEmployeeProcessor */ + private $assignEmployeeProcessor; + + /** @var AssignSegmentProcessor */ + private $assignSegmentProcessor; + + /** @var AuthenticationProcessor */ + private $authenticationProcessor; + + /** @var GenerateEmailVerificationAttemptProcessor */ + private $generateEmailVerificationAttemptProcessor; + + /** + * CreateCustomerLogic constructor. + * @param CreateUserProcessor $createUserProcessor + * @param CreateCompanyProcessor $createCompanyProcessor + * @param CreateContactProcessor $createContactProcessor + * @param AssignEmployeeProcessor $assignEmployeeProcessor + * @param AssignSegmentProcessor $assignSegmentProcessor + * @param AuthenticationProcessor $authenticationProcessor + * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor + */ + public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateContactProcessor $createContactProcessor, AssignEmployeeProcessor $assignEmployeeProcessor, AssignSegmentProcessor $assignSegmentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor) + { + $this->createUserProcessor = $createUserProcessor; + $this->createCompanyProcessor = $createCompanyProcessor; + $this->createContactProcessor = $createContactProcessor; + $this->assignEmployeeProcessor = $assignEmployeeProcessor; + $this->assignSegmentProcessor = $assignSegmentProcessor; + $this->authenticationProcessor = $authenticationProcessor; + $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\AccessUnauthorisedException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @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(['local']) ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION); + + /** @var Company $company */ + $company = $this->createCompanyProcessor->execute($request, BusinessType::IMPORTER, $request->input('type'), ApprovalStatus::PENDING_SUBMISSION); + + $this->createContactProcessor->execute($request, $company); + + $Object = new EmploymentObject($company, $user); + $this->assignEmployeeProcessor->execute($Object); + + $this->assignSegmentProcessor->execute($company); + + $this->generateEmailVerificationAttemptProcessor->execute($user); + + return $this->response($this->authenticationProcessor->execute($request)); + } +}