Make sure proper fares are returned from the API #899
This commit is contained in:
parent
b83f7dcac8
commit
1be68d1e63
@ -92,8 +92,9 @@ class CreateDatabase extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->option('reset') === true) {
|
if ($this->option('reset') === true) {
|
||||||
$cmd = ['rm', '-rf', config($dbkey.'database')];
|
if (file_exists($dbPath)) {
|
||||||
$this->runCommand($cmd);
|
unlink(config($dbkey.'database'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($dbPath)) {
|
if (!file_exists($dbPath)) {
|
||||||
|
@ -54,9 +54,13 @@ class FlightController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function get($id)
|
public function get($id)
|
||||||
{
|
{
|
||||||
|
/** @var \App\Models\User $user */
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
|
/** @var \App\Models\Flight $flight */
|
||||||
$flight = $this->flightRepo->with([
|
$flight = $this->flightRepo->with([
|
||||||
'airline',
|
'airline',
|
||||||
|
'fares',
|
||||||
'subfleets',
|
'subfleets',
|
||||||
'subfleets.aircraft',
|
'subfleets.aircraft',
|
||||||
'subfleets.fares',
|
'subfleets.fares',
|
||||||
@ -66,7 +70,7 @@ class FlightController extends Controller
|
|||||||
},
|
},
|
||||||
])->find($id);
|
])->find($id);
|
||||||
|
|
||||||
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
|
$flight = $this->flightSvc->filterSubfleets($user, $flight);
|
||||||
|
|
||||||
return new FlightResource($flight);
|
return new FlightResource($flight);
|
||||||
}
|
}
|
||||||
@ -109,6 +113,7 @@ class FlightController extends Controller
|
|||||||
$flights = $this->flightRepo
|
$flights = $this->flightRepo
|
||||||
->with([
|
->with([
|
||||||
'airline',
|
'airline',
|
||||||
|
'fares',
|
||||||
'subfleets',
|
'subfleets',
|
||||||
'subfleets.aircraft',
|
'subfleets.aircraft',
|
||||||
'subfleets.fares',
|
'subfleets.fares',
|
||||||
@ -124,7 +129,7 @@ class FlightController extends Controller
|
|||||||
|
|
||||||
// TODO: Remove any flights here that a user doesn't have permissions to
|
// TODO: Remove any flights here that a user doesn't have permissions to
|
||||||
foreach ($flights as $flight) {
|
foreach ($flights as $flight) {
|
||||||
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
|
$this->flightSvc->filterSubfleets($user, $flight);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FlightResource::collection($flights);
|
return FlightResource::collection($flights);
|
||||||
|
@ -61,7 +61,8 @@ class UserController extends Controller
|
|||||||
*/
|
*/
|
||||||
protected function getUserId(Request $request)
|
protected function getUserId(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->get('id') === null) {
|
$id = $request->get('id');
|
||||||
|
if ($id === null || $id === 'me') {
|
||||||
return Auth::user()->id;
|
return Auth::user()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Resources;
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
use App\Contracts\Resource;
|
use App\Contracts\Resource;
|
||||||
|
use App\Services\FareService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \App\Models\Fare
|
* @mixin \App\Models\Fare
|
||||||
@ -11,13 +12,17 @@ class Fare extends Resource
|
|||||||
{
|
{
|
||||||
public function toArray($request)
|
public function toArray($request)
|
||||||
{
|
{
|
||||||
|
/** @var FareService $fareSvc */
|
||||||
|
$fareSvc = app(FareService::class);
|
||||||
|
$fare = $fareSvc->getFares($this);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $fare->id,
|
||||||
'code' => $this->code,
|
'code' => $fare->code,
|
||||||
'name' => $this->name,
|
'name' => $fare->name,
|
||||||
'price' => $this->price,
|
'capacity' => $fare->capacity,
|
||||||
'cost' => $this->cost,
|
'cost' => $fare->cost,
|
||||||
'capacity' => $this->capacity,
|
'price' => $fare->price,
|
||||||
'type' => $this->type,
|
'type' => $this->type,
|
||||||
'notes' => $this->notes,
|
'notes' => $this->notes,
|
||||||
'active' => $this->active,
|
'active' => $this->active,
|
||||||
|
@ -58,6 +58,7 @@ class Flight extends Resource
|
|||||||
|
|
||||||
$res['airline'] = new Airline($this->airline);
|
$res['airline'] = new Airline($this->airline);
|
||||||
$res['subfleets'] = Subfleet::collection($this->whenLoaded('subfleets'));
|
$res['subfleets'] = Subfleet::collection($this->whenLoaded('subfleets'));
|
||||||
|
$res['fares'] = Fare::collection($this->whenLoaded('fares'));
|
||||||
$res['fields'] = $this->setFields();
|
$res['fields'] = $this->setFields();
|
||||||
|
|
||||||
// Simbrief info
|
// Simbrief info
|
||||||
|
@ -580,6 +580,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::post('user/bids', 'UserController@bids');
|
Route::post('user/bids', 'UserController@bids');
|
||||||
Route::delete('user/bids', 'UserController@bids');
|
Route::delete('user/bids', 'UserController@bids');
|
||||||
|
|
||||||
|
Route::get('users/me', 'UserController@index');
|
||||||
Route::get('users/{id}', 'UserController@get');
|
Route::get('users/{id}', 'UserController@get');
|
||||||
Route::get('users/{id}/fleet', 'UserController@fleet');
|
Route::get('users/{id}/fleet', 'UserController@fleet');
|
||||||
Route::get('users/{id}/pireps', 'UserController@pireps');
|
Route::get('users/{id}/pireps', 'UserController@pireps');
|
||||||
|
@ -45,6 +45,7 @@ class BidService extends Service
|
|||||||
{
|
{
|
||||||
$bids = Bid::with([
|
$bids = Bid::with([
|
||||||
'flight',
|
'flight',
|
||||||
|
'flight.fares',
|
||||||
'flight.simbrief',
|
'flight.simbrief',
|
||||||
'flight.subfleets',
|
'flight.subfleets',
|
||||||
'flight.subfleets.aircraft',
|
'flight.subfleets.aircraft',
|
||||||
|
@ -60,13 +60,13 @@ class FareService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get fares
|
* Get a fare with the proper prices/costs populated in the pivot
|
||||||
*
|
*
|
||||||
* @param $fare
|
* @param $fare
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function getFares($fare)
|
public function getFares($fare)
|
||||||
{
|
{
|
||||||
$pivot = $fare->pivot;
|
$pivot = $fare->pivot;
|
||||||
if (filled($pivot->price)) {
|
if (filled($pivot->price)) {
|
||||||
|
@ -16,6 +16,7 @@ use App\Support\Units\Time;
|
|||||||
class FlightService extends Service
|
class FlightService extends Service
|
||||||
{
|
{
|
||||||
private $airportSvc;
|
private $airportSvc;
|
||||||
|
private $fareSvc;
|
||||||
private $flightRepo;
|
private $flightRepo;
|
||||||
private $navDataRepo;
|
private $navDataRepo;
|
||||||
private $userSvc;
|
private $userSvc;
|
||||||
@ -24,17 +25,20 @@ class FlightService extends Service
|
|||||||
* FlightService constructor.
|
* FlightService constructor.
|
||||||
*
|
*
|
||||||
* @param AirportService $airportSvc
|
* @param AirportService $airportSvc
|
||||||
|
* @param FareService $fareSvc
|
||||||
* @param FlightRepository $flightRepo
|
* @param FlightRepository $flightRepo
|
||||||
* @param NavdataRepository $navdataRepo
|
* @param NavdataRepository $navdataRepo
|
||||||
* @param UserService $userSvc
|
* @param UserService $userSvc
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AirportService $airportSvc,
|
AirportService $airportSvc,
|
||||||
|
FareService $fareSvc,
|
||||||
FlightRepository $flightRepo,
|
FlightRepository $flightRepo,
|
||||||
NavdataRepository $navdataRepo,
|
NavdataRepository $navdataRepo,
|
||||||
UserService $userSvc
|
UserService $userSvc
|
||||||
) {
|
) {
|
||||||
$this->airportSvc = $airportSvc;
|
$this->airportSvc = $airportSvc;
|
||||||
|
$this->fareSvc = $fareSvc;
|
||||||
$this->flightRepo = $flightRepo;
|
$this->flightRepo = $flightRepo;
|
||||||
$this->navDataRepo = $navdataRepo;
|
$this->navDataRepo = $navdataRepo;
|
||||||
$this->userSvc = $userSvc;
|
$this->userSvc = $userSvc;
|
||||||
|
@ -16,6 +16,7 @@ use App\Models\Subfleet;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\ExpenseRepository;
|
use App\Repositories\ExpenseRepository;
|
||||||
use App\Repositories\JournalRepository;
|
use App\Repositories\JournalRepository;
|
||||||
|
use App\Services\BidService;
|
||||||
use App\Services\FareService;
|
use App\Services\FareService;
|
||||||
use App\Services\Finance\PirepFinanceService;
|
use App\Services\Finance\PirepFinanceService;
|
||||||
use App\Services\FleetService;
|
use App\Services\FleetService;
|
||||||
@ -235,12 +236,130 @@ class FinanceTest extends TestCase
|
|||||||
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
$this->assertEquals($fare->capacity, $subfleet_fares->get(0)->capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure that the API is returning the fares properly for a subfleet on a flight
|
||||||
|
* https://github.com/nabeelio/phpvms/issues/899
|
||||||
|
*/
|
||||||
|
public function testFlightFaresOverAPI()
|
||||||
|
{
|
||||||
|
$this->updateSetting('pireps.only_aircraft_at_dpt_airport', false);
|
||||||
|
$this->updateSetting('pireps.restrict_aircraft_to_rank', false);
|
||||||
|
|
||||||
|
$this->user = factory(User::class)->create();
|
||||||
|
|
||||||
|
/** @var Flight $flight */
|
||||||
|
$flight = factory(Flight::class)->create();
|
||||||
|
|
||||||
|
/** @var Subfleet $subfleet */
|
||||||
|
$subfleet = factory(Subfleet::class)->create();
|
||||||
|
$this->fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
||||||
|
|
||||||
|
/** @var Fare $fare */
|
||||||
|
$fare = factory(Fare::class)->create();
|
||||||
|
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare);
|
||||||
|
$flight_fares = $this->fareSvc->getForFlight($flight);
|
||||||
|
|
||||||
|
$this->assertCount(1, $flight_fares);
|
||||||
|
$this->assertEquals($fare->price, $flight_fares->get(0)->price);
|
||||||
|
$this->assertEquals($fare->capacity, $flight_fares->get(0)->capacity);
|
||||||
|
|
||||||
|
//
|
||||||
|
// set an override now (but on the flight)
|
||||||
|
//
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare, ['price' => 50]);
|
||||||
|
|
||||||
|
$req = $this->get('/api/flights/'.$flight->id);
|
||||||
|
$req->assertStatus(200);
|
||||||
|
|
||||||
|
$body = $req->json()['data'];
|
||||||
|
$this->assertEquals($flight->id, $body['id']);
|
||||||
|
$this->assertCount(1, $body['subfleets']);
|
||||||
|
$this->assertEquals(50, $body['fares'][0]['price']);
|
||||||
|
$this->assertEquals($fare->capacity, $body['fares'][0]['capacity']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlightFaresOverAPIOnUserBids()
|
||||||
|
{
|
||||||
|
$this->updateSetting('pireps.only_aircraft_at_dpt_airport', false);
|
||||||
|
$this->updateSetting('pireps.restrict_aircraft_to_rank', false);
|
||||||
|
|
||||||
|
/** @var BidService $bidSvc */
|
||||||
|
$bidSvc = app(BidService::class);
|
||||||
|
|
||||||
|
$this->user = factory(User::class)->create();
|
||||||
|
|
||||||
|
/** @var Flight $flight */
|
||||||
|
$flight = factory(Flight::class)->create();
|
||||||
|
|
||||||
|
/** @var Subfleet $subfleet */
|
||||||
|
$subfleet = factory(Subfleet::class)->create();
|
||||||
|
$this->fleetSvc->addSubfleetToFlight($subfleet, $flight);
|
||||||
|
|
||||||
|
/** @var Fare $fare */
|
||||||
|
$fare = factory(Fare::class)->create();
|
||||||
|
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare);
|
||||||
|
$flight_fares = $this->fareSvc->getForFlight($flight);
|
||||||
|
|
||||||
|
$this->assertCount(1, $flight_fares);
|
||||||
|
$this->assertEquals($fare->price, $flight_fares->get(0)->price);
|
||||||
|
$this->assertEquals($fare->capacity, $flight_fares->get(0)->capacity);
|
||||||
|
|
||||||
|
//
|
||||||
|
// set an override now (but on the flight)
|
||||||
|
//
|
||||||
|
$this->fareSvc->setForFlight($flight, $fare, ['price' => 50]);
|
||||||
|
$bid = $bidSvc->addBid($flight, $this->user);
|
||||||
|
|
||||||
|
$req = $this->get('/api/user/bids');
|
||||||
|
$req->assertStatus(200);
|
||||||
|
|
||||||
|
$body = $req->json()['data'];
|
||||||
|
$this->assertEquals($flight->id, $body[0]['flight_id']);
|
||||||
|
$this->assertCount(1, $body[0]['flight']['subfleets']);
|
||||||
|
$this->assertEquals(50, $body[0]['flight']['fares'][0]['price']);
|
||||||
|
$this->assertEquals($fare->capacity, $body[0]['flight']['fares'][0]['capacity']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSubfleetFaresOverAPI()
|
||||||
|
{
|
||||||
|
$this->updateSetting('pireps.only_aircraft_at_dpt_airport', false);
|
||||||
|
$this->updateSetting('pireps.restrict_aircraft_to_rank', false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a user and flights
|
||||||
|
*/
|
||||||
|
$this->user = factory(User::class)->create();
|
||||||
|
$flight = $this->addFlight($this->user);
|
||||||
|
|
||||||
|
/** @var FareService $fare_svc */
|
||||||
|
$fare_svc = app(FareService::class);
|
||||||
|
|
||||||
|
/** @var \App\Models\Fare $fare */
|
||||||
|
$fare = factory(Fare::class)->create();
|
||||||
|
$fare_svc->setForSubfleet($flight->subfleets[0], $fare, ['price' => 50]);
|
||||||
|
|
||||||
|
// Get from API
|
||||||
|
$req = $this->get('/api/flights/'.$flight->id);
|
||||||
|
$req->assertStatus(200);
|
||||||
|
|
||||||
|
$body = $req->json()['data'];
|
||||||
|
$this->assertEquals($flight->id, $body['id']);
|
||||||
|
$this->assertCount(1, $body['subfleets']);
|
||||||
|
$this->assertEquals(50, $body['subfleets'][0]['fares'][0]['price']);
|
||||||
|
$this->assertEquals($fare->capacity, $body['subfleets'][0]['fares'][0]['capacity']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign percentage values and make sure they're valid
|
* Assign percentage values and make sure they're valid
|
||||||
*/
|
*/
|
||||||
public function testFlightFareOverrideAsPercent()
|
public function testFlightFareOverrideAsPercent()
|
||||||
{
|
{
|
||||||
|
/** @var Flight $flight */
|
||||||
$flight = factory(Flight::class)->create();
|
$flight = factory(Flight::class)->create();
|
||||||
|
|
||||||
|
/** @var \App\Models\Fare $fare */
|
||||||
$fare = factory(Fare::class)->create();
|
$fare = factory(Fare::class)->create();
|
||||||
|
|
||||||
$percent_incr = '20%';
|
$percent_incr = '20%';
|
||||||
|
@ -33,50 +33,6 @@ class FlightTest extends TestCase
|
|||||||
$this->settingsRepo = app(SettingRepository::class);
|
$this->settingsRepo = app(SettingRepository::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a single flight
|
|
||||||
*
|
|
||||||
* @param $user
|
|
||||||
* @param array $flight_properties
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function addFlight($user, $flight_properties = [])
|
|
||||||
{
|
|
||||||
$opts = array_merge([
|
|
||||||
'airline_id' => $user->airline_id,
|
|
||||||
], $flight_properties);
|
|
||||||
|
|
||||||
$flight = factory(Flight::class)->create($opts);
|
|
||||||
|
|
||||||
$flight->subfleets()->syncWithoutDetaching([
|
|
||||||
factory(Subfleet::class)->create([
|
|
||||||
'airline_id' => $user->airline_id,
|
|
||||||
])->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $flight;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a given number of flights for a subfleet
|
|
||||||
*
|
|
||||||
* @param $subfleet
|
|
||||||
* @param $num_flights
|
|
||||||
*
|
|
||||||
* @return \App\Models\Flight[]
|
|
||||||
*/
|
|
||||||
public function addFlightsForSubfleet($subfleet, $num_flights)
|
|
||||||
{
|
|
||||||
return factory(Flight::class, $num_flights)->create([
|
|
||||||
'airline_id' => $subfleet->airline->id,
|
|
||||||
])->each(function (Flight $f) use ($subfleet) {
|
|
||||||
$f->subfleets()->syncWithoutDetaching([
|
|
||||||
$subfleet->id,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test adding a flight and also if there are duplicates
|
* Test adding a flight and also if there are duplicates
|
||||||
*/
|
*/
|
||||||
@ -468,7 +424,11 @@ class FlightTest extends TestCase
|
|||||||
public function testFlightSearchApiDistance()
|
public function testFlightSearchApiDistance()
|
||||||
{
|
{
|
||||||
$total_flights = 10;
|
$total_flights = 10;
|
||||||
|
|
||||||
|
/** @var \App\Models\User user */
|
||||||
$this->user = factory(User::class)->create();
|
$this->user = factory(User::class)->create();
|
||||||
|
|
||||||
|
/** @var \App\Models\Flight $flights */
|
||||||
$flights = factory(Flight::class, $total_flights)->create([
|
$flights = factory(Flight::class, $total_flights)->create([
|
||||||
'airline_id' => $this->user->airline_id,
|
'airline_id' => $this->user->airline_id,
|
||||||
]);
|
]);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\Fare;
|
use App\Models\Fare;
|
||||||
use App\Models\Subfleet;
|
|
||||||
use App\Services\FareService;
|
use App\Services\FareService;
|
||||||
|
|
||||||
class SubfleetTest extends TestCase
|
class SubfleetTest extends TestCase
|
||||||
@ -19,9 +18,15 @@ class SubfleetTest extends TestCase
|
|||||||
|
|
||||||
public function testSubfleetFaresNoOverride()
|
public function testSubfleetFaresNoOverride()
|
||||||
{
|
{
|
||||||
|
/** @var FareService $fare_svc */
|
||||||
$fare_svc = app(FareService::class);
|
$fare_svc = app(FareService::class);
|
||||||
|
|
||||||
$subfleet = factory(Subfleet::class)->create();
|
$subfleet_aircraft = $this->createSubfleetWithAircraft(1);
|
||||||
|
|
||||||
|
/** @var \App\Models\Subfleet $subfleet */
|
||||||
|
$subfleet = $subfleet_aircraft['subfleet'];
|
||||||
|
|
||||||
|
/** @var \App\Models\Fare $fare */
|
||||||
$fare = factory(Fare::class)->create();
|
$fare = factory(Fare::class)->create();
|
||||||
|
|
||||||
$fare_svc->setForSubfleet($subfleet, $fare);
|
$fare_svc->setForSubfleet($subfleet, $fare);
|
||||||
@ -49,40 +54,4 @@ class SubfleetTest extends TestCase
|
|||||||
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
||||||
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubfleetFaresOverride()
|
|
||||||
{
|
|
||||||
$fare_svc = app(FareService::class);
|
|
||||||
|
|
||||||
$subfleet = factory(Subfleet::class)->create();
|
|
||||||
$fare = factory(Fare::class)->create();
|
|
||||||
|
|
||||||
$fare_svc->setForSubfleet($subfleet, $fare, [
|
|
||||||
'price' => 50, 'capacity' => 400,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
|
||||||
|
|
||||||
$this->assertCount(1, $ac_fares);
|
|
||||||
$this->assertEquals(50, $ac_fares[0]->price);
|
|
||||||
$this->assertEquals(400, $ac_fares[0]->capacity);
|
|
||||||
|
|
||||||
//
|
|
||||||
// update the override to a different amount and make sure it updates
|
|
||||||
//
|
|
||||||
|
|
||||||
$fare_svc->setForSubfleet($subfleet, $fare, [
|
|
||||||
'price' => 150, 'capacity' => 50,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$ac_fares = $fare_svc->getForSubfleet($subfleet);
|
|
||||||
|
|
||||||
$this->assertCount(1, $ac_fares);
|
|
||||||
$this->assertEquals(150, $ac_fares[0]->price);
|
|
||||||
$this->assertEquals(50, $ac_fares[0]->capacity);
|
|
||||||
|
|
||||||
// delete
|
|
||||||
$fare_svc->delFareFromSubfleet($subfleet, $fare);
|
|
||||||
$this->assertCount(0, $fare_svc->getForSubfleet($subfleet));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
|
use App\Models\Flight;
|
||||||
use App\Models\Subfleet;
|
use App\Models\Subfleet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -74,6 +75,49 @@ trait TestData
|
|||||||
return $rank;
|
return $rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a single flight
|
||||||
|
*
|
||||||
|
* @param $user
|
||||||
|
* @param array $flight_properties
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function addFlight($user, $flight_properties = [])
|
||||||
|
{
|
||||||
|
$opts = array_merge([
|
||||||
|
'airline_id' => $user->airline_id,
|
||||||
|
], $flight_properties);
|
||||||
|
|
||||||
|
$flight = factory(Flight::class)->create($opts);
|
||||||
|
|
||||||
|
$flight->subfleets()->syncWithoutDetaching([
|
||||||
|
factory(Subfleet::class)->create([
|
||||||
|
'airline_id' => $user->airline_id,
|
||||||
|
])->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $flight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a given number of flights for a subfleet
|
||||||
|
*
|
||||||
|
* @param $subfleet
|
||||||
|
* @param $num_flights
|
||||||
|
*
|
||||||
|
* @return \App\Models\Flight[]
|
||||||
|
*/
|
||||||
|
public function addFlightsForSubfleet($subfleet, $num_flights)
|
||||||
|
{
|
||||||
|
return factory(Flight::class, $num_flights)->create([
|
||||||
|
'airline_id' => $subfleet->airline->id,
|
||||||
|
])->each(function (Flight $f) use ($subfleet) {
|
||||||
|
$f->subfleets()->syncWithoutDetaching([$subfleet->id]);
|
||||||
|
$f->refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a subfleet with a number of aircraft assigned
|
* Create a subfleet with a number of aircraft assigned
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user