mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Documents\ControllersLogic;
|
|
|
|
use App\Http\Resources\DocumentResource;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
|
|
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
|
|
|
use App\Classes\Modules\Documents\Standards\Rules\CanUpdateDocument;
|
|
use App\Classes\Modules\Documents\Services\ApprovesDocument;
|
|
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
|
|
|
use App\Classes\ValueObjects\Constants\ObjectStatus;
|
|
|
|
use ErrorException;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ApproveDocumentLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Approve Document',
|
|
'message' => 'You have successfully approved the Document'
|
|
];
|
|
}
|
|
|
|
/** @var CanUpdateDocument */
|
|
private $canUpdateDocument;
|
|
|
|
/** @var ApprovesDocument */
|
|
private $approvesDocument;
|
|
|
|
/** @var FetchesDocument */
|
|
private $fetchesDocument;
|
|
|
|
/**
|
|
* UpdateStandardSegmentConstantLogic constructor.
|
|
* @param CanUpdateDocument $canUpdateDocument
|
|
* @param ApprovesDocument $approvesDocument
|
|
* @param FetchesDocument $fetchesDocument
|
|
*/
|
|
public function __construct(
|
|
canUpdateDocument $canUpdateDocument,
|
|
ApprovesDocument $approvesDocument,
|
|
FetchesDocument $fetchesDocument
|
|
)
|
|
{
|
|
$this->canUpdateDocument = $canUpdateDocument;
|
|
$this->approvesDocument = $approvesDocument;
|
|
$this->fetchesDocument = $fetchesDocument;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws ErrorException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$document_query = $this->fetchesDocument->execute(['id' => $request->route('id')]);
|
|
|
|
$document_object = new DocumentObject(
|
|
$document_query->owner_id,
|
|
$document_query->owner_type,
|
|
$document_query->document_type,
|
|
$document_query->reference,
|
|
ObjectStatus::ACTIVE,
|
|
\Auth::user()->id,
|
|
$document_query->issued_date,
|
|
$document_query->expired_date,
|
|
$document_query->approved_date
|
|
);
|
|
$this->canUpdateDocument->passes($document_object);
|
|
$document_query = $this->approvesDocument->execute($document_query, $document_object);
|
|
|
|
DB::commit();
|
|
|
|
return $this->resourceResponse(new DocumentResource($document_query));
|
|
|
|
} catch (\Exception $exception){
|
|
dd($exception);
|
|
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
|
}
|
|
}
|
|
|
|
} |