'Created User', 'message' => 'You have successfully created a new User' ]; } /** @var CreateUserProcessor */ private $createUserProcessor; /** @var CreateContactProcessor */ private $createContactProcessor; /** @var FetchesCompany */ private $fetchesCompany; /** @var AssignEmployeeProcessor */ private $assignEmployeeProcessor; /** @var AuthenticationProcessor */ private $authenticationProcessor; /** * CreateInvitedCustomerLogic constructor. * @param CreateUserProcessor $createUserProcessor * @param CreateContactProcessor $createContactProcessor * @param FetchesCompany $fetchesCompany * @param AssignEmployeeProcessor $assignEmployeeProcessor * @param AuthenticationProcessor $authenticationProcessor */ public function __construct(CreateUserProcessor $createUserProcessor, CreateContactProcessor $createContactProcessor, FetchesCompany $fetchesCompany, AssignEmployeeProcessor $assignEmployeeProcessor, AuthenticationProcessor $authenticationProcessor) { $this->createUserProcessor = $createUserProcessor; $this->createContactProcessor = $createContactProcessor; $this->fetchesCompany = $fetchesCompany; $this->assignEmployeeProcessor = $assignEmployeeProcessor; $this->authenticationProcessor = $authenticationProcessor; } /** * @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 Company $company */ $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); /** @var CompanyModule $companyModule */ $companyModule = $company->companyModules()->first(); if($companyModule->employees()->exists()){ throw new AccessForbiddenException('This company\'s account has been claimed by another user already!'); } /** @var User $user */ $user = $this->createUserProcessor->execute($request, RoleTypes::USER, !App::environment(['production']) ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION); $contactObject = new ContactObject($request->input('name'), $request->input('phone'), $request->input('contact_email'), $request->input('wechat_id')); $this->createContactProcessor->execute($contactObject, $company); $Object = new EmploymentObject($companyModule, $user); $this->assignEmployeeProcessor->execute($Object); return $this->response($this->authenticationProcessor->execute($request)); } }