move notification API and UI from shipping portal

This commit is contained in:
edmondlang
2022-04-16 23:53:12 +08:00
parent a79cb718d9
commit 29b1f87966
18 changed files with 597 additions and 32 deletions
@@ -13,6 +13,9 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Documents\Services\FetchesDocument;
use App\Classes\Modules\Documents\Services\ApprovesDocument;
use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
Use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor;
use App\Classes\General\Interfaces\Notifiable;
use App\Models\Document;
use Illuminate\Http\JsonResponse;
@@ -46,6 +49,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
/** @var UpdatesCompanyStatus */
private $updatesCompanyStatus;
/** @var CreateNotificationProcessor */
private $createNotificationProcessor;
/**
* ApproveIdentificationDocumentLogic constructor.
* @param CanApproveDocument $canApproveDocument
@@ -53,14 +59,16 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
* @param RejectsDocument $rejectsDocument
* @param FetchesDocument $fetchesDocument
* @param UpdatesCompanyStatus $updatesCompanyStatus
* @param CreateNotificationProcessor $createNotificationProcessor
*/
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus)
public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, CreateNotificationProcessor $createNotificationProcessor)
{
$this->canApproveDocument = $canApproveDocument;
$this->approvesDocument = $approvesDocument;
$this->rejectsDocument = $rejectsDocument;
$this->fetchesDocument = $fetchesDocument;
$this->updatesCompanyStatus = $updatesCompanyStatus;
$this->createNotificationProcessor = $createNotificationProcessor;
}
/**
@@ -84,6 +92,20 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic
$this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
$object = new NotificationObject(
'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ),
( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ),
$document->owner,
$document->owner->employees()->first(),
$document,
);
$this->createNotificationProcessor->execute($object);
if($status === 'approve'){
$orders = $this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED);
}
return $this->resourceResponse(new DocumentResource($document));
}