mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Documents\Services;
|
|
|
|
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Document;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class RejectsDocument extends AbstractUpdateRecord
|
|
{
|
|
|
|
/**
|
|
* @param Document $model
|
|
* @return \Illuminate\Database\Eloquent\Model
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
*/
|
|
public function execute(Document $model)
|
|
{
|
|
$user = Auth()->user();
|
|
// if auth user is null, then this services is calling from exchange
|
|
if (!$user) {
|
|
$token = explode('.', request()->bearerToken())[1];
|
|
$decodedToken = base64_decode($token);
|
|
$exchangeUser = json_decode($decodedToken, true)['user'];
|
|
$user = User::where('email', $exchangeUser['email'])->first();
|
|
if (!$user) {
|
|
$user = User::find(1);
|
|
}
|
|
}
|
|
$model->status = ApprovalStatus::REJECTED;
|
|
$model->approver = $user->id;
|
|
$model->approval_date = Carbon::now();
|
|
|
|
return $this->handler($model);
|
|
}
|
|
} |