mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Code sync from Shipping Portal, independent deployment of Vue Polling, Performance Improvement and tweaking for better user experience
This commit is contained in:
@@ -15,18 +15,9 @@ use App\Models\SegmentConstant;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CompanyResource extends JsonResource
|
||||
{
|
||||
private $userInfo;
|
||||
|
||||
public function __construct($resource, $userInfo = null)
|
||||
{
|
||||
parent::__construct($resource);
|
||||
$this->userInfo = $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
@@ -41,26 +32,6 @@ class CompanyResource extends JsonResource
|
||||
$segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first();
|
||||
$serviceCharge = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $this->id)->first();
|
||||
|
||||
$userResource = null;
|
||||
|
||||
$userInfoEmail = $this->userInfo && isset($this->userInfo->email) ? $this->userInfo->email : null;
|
||||
$userInfoType = $this->userInfo && isset($this->userInfo->type) ? $this->userInfo->type : null;
|
||||
|
||||
if(!$userInfoEmail && Auth::user()){
|
||||
$userInfoEmail = Auth::user()->email;
|
||||
}
|
||||
if(!$userInfoType && Auth::user()){
|
||||
$userInfoType = Auth::user()->type;
|
||||
}
|
||||
|
||||
//cief todo: remove
|
||||
// Log::error('CompanyResource 1: '. json_encode($userInfoEmail));
|
||||
// Log::error('CompanyResource 2: '. json_encode($userInfoType));
|
||||
|
||||
if(!is_null($userInfoEmail) && !is_null($userInfoType)){
|
||||
$userResource = new UserResource($userInfoType === RoleTypes::USER ? $this->employees()->where('email', '=', $userInfoEmail)->first() : $this->employees()->orderBy('id', 'DESC')->first());
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
@@ -71,8 +42,7 @@ class CompanyResource extends JsonResource
|
||||
'status' => (int) $this->status,
|
||||
'contact' => new ContactResource ($this->when($this->has('contacts'), $this->contacts->first())),
|
||||
'address' => new AddressResource($this->when($this->has('addresses'), $this->addresses->where('billing', true)->first())),
|
||||
//cief todo: this one need to decide what to do to replace Auth:user() when it is run by job queue
|
||||
'employee' => $userResource,
|
||||
'employee' => new UserResource(Auth::user()->type === RoleTypes::USER ? $this->employees()->where('email', '=', Auth::user()->email)->first() : $this->employees()->orderBy('id', 'DESC')->first()),
|
||||
'identification' => new DocumentResource($this->documents->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->first()),
|
||||
'bookings' => $this->whenLoaded('bookings', $this->bookings()->orderBy('id', 'DESC')->get(), []),
|
||||
'confirmed_bookings' => $this->bookings()->whereHas('transactions', function ($query){
|
||||
|
||||
Reference in New Issue
Block a user