Return the flight fares if there are no subfleet fares #488 (#489)

* Return the flight fares if there are no subfleet fares #488

* Formatting

* Formatting
This commit is contained in:
Nabeel S 2020-01-06 13:44:43 -05:00 committed by GitHub
parent 282cb4be95
commit 74052e4542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 28 deletions

View File

@ -25,8 +25,8 @@ class MeasureExecutionTime implements Middleware
// I assume you're using valid json in your responses // I assume you're using valid json in your responses
// Then I manipulate them below // Then I manipulate them below
$content = json_decode($response->getContent(), true) + [ $content = json_decode($response->getContent(), true) + [
'execution_time' => $executionTime, 'execution_time' => $executionTime,
]; ];
// Change the content of your response // Change the content of your response
$response->setData($content); $response->setData($content);

View File

@ -67,7 +67,7 @@ class File extends Model
* *
* @return string * @return string
*/ */
public function getFilenameAttribute() :string public function getFilenameAttribute(): string
{ {
if (!$this->pathinfo) { if (!$this->pathinfo) {
$this->pathinfo = pathinfo($this->path); $this->pathinfo = pathinfo($this->path);

View File

@ -146,7 +146,7 @@ class User extends Authenticatable
} }
return new File([ return new File([
'path' => $this->attributes['avatar'], 'path' => $this->attributes['avatar'],
]); ]);
} }

View File

@ -34,7 +34,14 @@ class FareService extends Service
$flight_fares = $this->getForFlight($flight); $flight_fares = $this->getForFlight($flight);
} }
if (empty($subfleet)) {
return $flight_fares;
}
$subfleet_fares = $this->getForSubfleet($subfleet); $subfleet_fares = $this->getForSubfleet($subfleet);
if (empty($subfleet_fares) || $subfleet_fares->count() === 0) {
return $flight_fares;
}
// Go through all of the fares assigned by the subfleet // Go through all of the fares assigned by the subfleet
// See if any of the same fares are assigned to the flight // See if any of the same fares are assigned to the flight
@ -60,7 +67,7 @@ class FareService extends Service
protected function getFares($fare) protected function getFares($fare)
{ {
if (filled($fare->pivot->price)) { if (filled($fare->pivot->price)) {
if (substr_count($fare->pivot->price, '%', -1)) { if (strpos($fare->pivot->price, '%', -1) !== false) {
$fare->price = Math::addPercent($fare->price, $fare->pivot->price); $fare->price = Math::addPercent($fare->price, $fare->pivot->price);
} else { } else {
$fare->price = $fare->pivot->price; $fare->price = $fare->pivot->price;
@ -68,7 +75,7 @@ class FareService extends Service
} }
if (filled($fare->pivot->cost)) { if (filled($fare->pivot->cost)) {
if (substr_count($fare->pivot->cost, '%', -1)) { if (strpos($fare->pivot->cost, '%', -1) !== false) {
$fare->cost = Math::addPercent($fare->cost, $fare->pivot->cost); $fare->cost = Math::addPercent($fare->cost, $fare->pivot->cost);
} else { } else {
$fare->cost = $fare->pivot->cost; $fare->cost = $fare->pivot->cost;
@ -76,7 +83,7 @@ class FareService extends Service
} }
if (filled($fare->pivot->capacity)) { if (filled($fare->pivot->capacity)) {
if (substr_count($fare->pivot->capacity, '%', -1)) { if (strpos($fare->pivot->capacity, '%', -1) !== false) {
$fare->capacity = Math::addPercent($fare->capacity, $fare->pivot->capacity); $fare->capacity = Math::addPercent($fare->capacity, $fare->pivot->capacity);
} else { } else {
$fare->capacity = $fare->pivot->capacity; $fare->capacity = $fare->pivot->capacity;

View File

@ -269,10 +269,10 @@ class PirepService extends Service
foreach ($field_values as $fv) { foreach ($field_values as $fv) {
PirepFieldValue::updateOrCreate( PirepFieldValue::updateOrCreate(
['pirep_id' => $pirep_id, ['pirep_id' => $pirep_id,
'name' => $fv['name'], 'name' => $fv['name'],
], ],
['value' => $fv['value'], ['value' => $fv['value'],
'source' => $fv['source'], 'source' => $fv['source'],
] ]
); );
} }

View File

@ -16,9 +16,9 @@ class RankImport extends BaseImporter
$count = 0; $count = 0;
foreach ($this->db->readRows($this->table, $start) as $row) { foreach ($this->db->readRows($this->table, $start) as $row) {
$rank = Rank::firstOrCreate(['name' => $row->rank], [ $rank = Rank::firstOrCreate(['name' => $row->rank], [
'image_url' => $row->rankimage, 'image_url' => $row->rankimage,
'hours' => $row->minhours, 'hours' => $row->minhours,
]); ]);
$this->idMapper->addMapping('ranks', $row->rankid, $rank->id); $this->idMapper->addMapping('ranks', $row->rankid, $rank->id);
$this->idMapper->addMapping('ranks', $row->rank, $rank->id); $this->idMapper->addMapping('ranks', $row->rank, $rank->id);

View File

@ -38,7 +38,7 @@ class ImporterDB
'host='.$this->creds['host'], 'host='.$this->creds['host'],
'port='.$this->creds['port'], 'port='.$this->creds['port'],
'dbname='.$this->creds['name'], 'dbname='.$this->creds['name'],
]); ]);
Log::info('Using DSN: '.$this->dsn); Log::info('Using DSN: '.$this->dsn);

View File

@ -21,19 +21,19 @@ class UpdateServiceProvider extends ServiceProvider
protected function registerRoutes() protected function registerRoutes()
{ {
Route::group([ Route::group([
'as' => 'update.', 'as' => 'update.',
'prefix' => 'update', 'prefix' => 'update',
'middleware' => ['auth', 'ability:admin,admin-access', 'web'], 'middleware' => ['auth', 'ability:admin,admin-access', 'web'],
'namespace' => 'Modules\Updater\Http\Controllers', 'namespace' => 'Modules\Updater\Http\Controllers',
], function () { ], function () {
Route::get('/', 'UpdateController@index')->name('index'); Route::get('/', 'UpdateController@index')->name('index');
Route::get('/step1', 'UpdateController@step1')->name('step1'); Route::get('/step1', 'UpdateController@step1')->name('step1');
Route::post('/step1', 'UpdateController@step1')->name('step1'); Route::post('/step1', 'UpdateController@step1')->name('step1');
Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations'); Route::post('/run-migrations', 'UpdateController@run_migrations')->name('run_migrations');
Route::get('/complete', 'UpdateController@complete')->name('complete'); Route::get('/complete', 'UpdateController@complete')->name('complete');
}); });
} }
/** /**

View File

@ -177,7 +177,7 @@ class FinanceTest extends TestCase
'capacity' => $percent_200, 'capacity' => $percent_200,
]); ]);
$ac_fares = $this->fareSvc->getForFlight($flight); $ac_fares = $this->fareSvc->getAllFares($flight, null);
$this->assertCount(1, $ac_fares); $this->assertCount(1, $ac_fares);
$this->assertEquals($new_price, $ac_fares[0]->price); $this->assertEquals($new_price, $ac_fares[0]->price);

View File

@ -37,7 +37,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
/** /**
* @throws Exception * @throws Exception
*/ */
public function setUp() : void public function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -52,7 +52,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
Artisan::call('migrate:refresh', ['--env' => 'testing']); Artisan::call('migrate:refresh', ['--env' => 'testing']);
} }
public function tearDown() : void public function tearDown(): void
{ {
parent::tearDown(); parent::tearDown();
} }