mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-20 21:13:59 +00:00
Admin Workflow - API code refactor to fetch booking information
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Questionnaires\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Questionnaires\Standards\Rules\CanFetchQuestion;
|
||||
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
|
||||
use App\Http\Resources\BookingBaseResource;
|
||||
use App\Models\Booking;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchAdminWFModelAttributesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Model Attributes for Admin Workflow ',
|
||||
'message' => 'You have successfully retrieved Model Attributes for Admin Workflow'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchQuestion */
|
||||
private $canFetchQuestion;
|
||||
|
||||
|
||||
/**
|
||||
* FetchAdminWFModelAttributesLogic constructor.
|
||||
* @param CanFetchQuestion $canFetchQuestion
|
||||
*/
|
||||
public function __construct(CanFetchQuestion $canFetchQuestion)
|
||||
{
|
||||
$this->canFetchQuestion = $canFetchQuestion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchQuestion->passes();
|
||||
|
||||
$booking = Booking::find($request->route('booking_id'));
|
||||
|
||||
if (!$booking) {
|
||||
return responseJson(null, 'No booking found', 404);
|
||||
}
|
||||
|
||||
$attributes = $booking->modelAttributes()
|
||||
->where('name', BookingAttributeNames::ORDER_REFERENCE_NO)
|
||||
->get(['id', 'value'])
|
||||
->map(fn ($attr) => $attr->only(['id', 'value']));
|
||||
|
||||
$transaction = $booking->bills()->first(); //cief todo: 74 - more than 1 record?
|
||||
return responseJson([
|
||||
'booking' => $booking,
|
||||
'booking_attributes' => $attributes,
|
||||
'reference' =>$transaction->owner->owner->marking,
|
||||
'marking' => $transaction->owner->owner->company->reference,
|
||||
'currency_rate' => $transaction->currency_rate,
|
||||
'total_amount' =>$transaction->currency->short_code . ' ' . number_format((float)$transaction->amount, 2, '.', '')
|
||||
]);
|
||||
|
||||
return $this->resourceResponse(new BookingBaseResource($booking));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user