Make sure proper fares are returned from the API #899
This commit is contained in:
@@ -54,9 +54,13 @@ class FlightController extends Controller
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
/** @var \App\Models\Flight $flight */
|
||||
$flight = $this->flightRepo->with([
|
||||
'airline',
|
||||
'fares',
|
||||
'subfleets',
|
||||
'subfleets.aircraft',
|
||||
'subfleets.fares',
|
||||
@@ -66,7 +70,7 @@ class FlightController extends Controller
|
||||
},
|
||||
])->find($id);
|
||||
|
||||
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
|
||||
$flight = $this->flightSvc->filterSubfleets($user, $flight);
|
||||
|
||||
return new FlightResource($flight);
|
||||
}
|
||||
@@ -109,6 +113,7 @@ class FlightController extends Controller
|
||||
$flights = $this->flightRepo
|
||||
->with([
|
||||
'airline',
|
||||
'fares',
|
||||
'subfleets',
|
||||
'subfleets.aircraft',
|
||||
'subfleets.fares',
|
||||
@@ -124,7 +129,7 @@ class FlightController extends Controller
|
||||
|
||||
// TODO: Remove any flights here that a user doesn't have permissions to
|
||||
foreach ($flights as $flight) {
|
||||
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
|
||||
$this->flightSvc->filterSubfleets($user, $flight);
|
||||
}
|
||||
|
||||
return FlightResource::collection($flights);
|
||||
|
||||
@@ -61,7 +61,8 @@ class UserController extends Controller
|
||||
*/
|
||||
protected function getUserId(Request $request)
|
||||
{
|
||||
if ($request->get('id') === null) {
|
||||
$id = $request->get('id');
|
||||
if ($id === null || $id === 'me') {
|
||||
return Auth::user()->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Contracts\Resource;
|
||||
use App\Services\FareService;
|
||||
|
||||
/**
|
||||
* @mixin \App\Models\Fare
|
||||
@@ -11,13 +12,17 @@ class Fare extends Resource
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
/** @var FareService $fareSvc */
|
||||
$fareSvc = app(FareService::class);
|
||||
$fare = $fareSvc->getFares($this);
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'price' => $this->price,
|
||||
'cost' => $this->cost,
|
||||
'capacity' => $this->capacity,
|
||||
'id' => $fare->id,
|
||||
'code' => $fare->code,
|
||||
'name' => $fare->name,
|
||||
'capacity' => $fare->capacity,
|
||||
'cost' => $fare->cost,
|
||||
'price' => $fare->price,
|
||||
'type' => $this->type,
|
||||
'notes' => $this->notes,
|
||||
'active' => $this->active,
|
||||
|
||||
@@ -58,6 +58,7 @@ class Flight extends Resource
|
||||
|
||||
$res['airline'] = new Airline($this->airline);
|
||||
$res['subfleets'] = Subfleet::collection($this->whenLoaded('subfleets'));
|
||||
$res['fares'] = Fare::collection($this->whenLoaded('fares'));
|
||||
$res['fields'] = $this->setFields();
|
||||
|
||||
// Simbrief info
|
||||
|
||||
Reference in New Issue
Block a user