Files
portal/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyIdentificationDocumentLogic.php
T
omair saleh 9fe0757baf big commit
2021-03-22 08:46:33 +08:00

100 lines
3.3 KiB
PHP

<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Accounts\Services\FetchesUser;
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFile;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\CompanyTypes;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\OwnerType;
use App\Http\Resources\CompanyResource;
use App\Http\Resources\DocumentResource;
use App\Models\Document;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateCompanyIdentificationDocumentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Company Identification',
'message' => 'You have successfully created a new Company Identification Document'
];
}
/** @var FetchesUser */
private $fetchesUser;
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFile */
private $createsFile;
/** @var UpdatesCompanyStatus */
private $updatesCompanyStatus;
/**
* UpdateCompanyIdentificationDocumentLogic constructor.
* @param FetchesUser $fetchesUser
* @param FetchesCompany $fetchesCompany
* @param CreatesDocument $createsDocument
* @param CreatesFile $createsFile
* @param UpdatesCompanyStatus $updatesCompanyStatus
*/
public function __construct(FetchesUser $fetchesUser, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFile $createsFile, UpdatesCompanyStatus $updatesCompanyStatus)
{
$this->fetchesUser = $fetchesUser;
$this->fetchesCompany = $fetchesCompany;
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
$this->updatesCompanyStatus = $updatesCompanyStatus;
}
/**
* @param Request $request
* @return JsonResponse
* @throws ErrorException
*/
public function logic(Request $request) : JsonResponse
{
try {
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
$object = new DocumentObject(
$company->type === CompanyTypes::COMPANY_BUSINESS ? DocumentType::SSM_REGISTRATION: DocumentType::IDENTITY_CARD,
$request->input('files'), $request->input('reference'));
/** @var Document $document */
$document = $this->createsDocument->execute($company, $object);
$this->createsFile->execute($document, $object);
$this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION);
return $this->resourceResponse(new DocumentResource($document));
} catch (\Exception $exception){
throw new ErrorException($exception->getMessage(), $exception->getCode());
}
}
}