Reset the criterea before a new search
This commit is contained in:
@@ -35,7 +35,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) {
|
||||
'start_date' => null,
|
||||
'end_date' => null,
|
||||
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
|
||||
'updated_at' => function (array $flight) {
|
||||
'updated_at' => static function (array $flight) {
|
||||
return $flight['created_at'];
|
||||
},
|
||||
];
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Repositories\Criteria\WhereCriteria;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Services\FlightService;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Prettus\Repository\Exceptions\RepositoryException;
|
||||
@@ -95,7 +96,9 @@ class FlightController extends Controller
|
||||
];
|
||||
|
||||
// Allow the option to bypass some of these restrictions for the searches
|
||||
if (!$request->filled('ignore_restrictions') || $request->ignore_restrictions === '0') {
|
||||
if (!$request->filled('ignore_restrictions')
|
||||
|| $request->get('ignore_restrictions') === '0'
|
||||
) {
|
||||
if (setting('pilots.restrict_to_company')) {
|
||||
$where['airline_id'] = Auth::user()->airline_id;
|
||||
}
|
||||
@@ -106,6 +109,7 @@ class FlightController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$this->flightRepo->resetCriteria();
|
||||
$this->flightRepo->searchCriteria($request);
|
||||
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
||||
|
||||
@@ -139,6 +139,8 @@ class FlightController extends Controller
|
||||
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
|
||||
}
|
||||
|
||||
$this->flightRepo->resetCriteria();
|
||||
|
||||
try {
|
||||
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||
} catch (RepositoryException $e) {
|
||||
|
||||
@@ -111,7 +111,7 @@ class FlightRepository extends Repository implements CacheableInterface
|
||||
|
||||
// Distance, less than
|
||||
if ($request->filled('dlt')) {
|
||||
$where[] = ['distance', '<', $request->dlt];
|
||||
$where[] = ['distance', '<=', $request->dlt];
|
||||
}
|
||||
|
||||
$this->pushCriteria(new WhereCriteria($request, $where));
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Exceptions\SettingNotFound;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
||||
if (!function_exists('in_mask')) {
|
||||
/**
|
||||
* Return true/false if a value exists in a mask
|
||||
@@ -109,7 +112,7 @@ if (!function_exists('skin_view')) {
|
||||
* @param array $vars
|
||||
* @param array $merge_data
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Factory|\Illuminate\View\View
|
||||
*/
|
||||
function skin_view($template, array $vars = [], array $merge_data = [])
|
||||
{
|
||||
@@ -136,7 +139,7 @@ if (!function_exists('setting')) {
|
||||
|
||||
try {
|
||||
$value = $settingRepo->retrieve($key);
|
||||
} catch (\App\Exceptions\SettingNotFound $e) {
|
||||
} catch (SettingNotFound $e) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ class FlightTest extends TestCase
|
||||
$flight->distance = 1500;
|
||||
$flight->save();
|
||||
|
||||
$distance_gt = 1000;
|
||||
$distance_gt = 1100;
|
||||
$distance_lt = 1600;
|
||||
|
||||
// look for all of the flights now less than the "factory default" of 1000
|
||||
@@ -370,6 +370,7 @@ class FlightTest extends TestCase
|
||||
$query = 'dgt='.$distance_gt.'&ignore_restrictions=1';
|
||||
$req = $this->get('/api/flights/search?'.$query);
|
||||
$body = $req->json();
|
||||
|
||||
$this->assertCount(1, $body['data']);
|
||||
$this->assertEquals($flight->id, $body['data'][0]['id']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user