Fix for aircraft not being detected at departure airport #781 (#789)

Aircraft not being checked/detected at departure airport #781
This commit is contained in:
Nabeel S
2020-08-17 16:44:31 -04:00
committed by GitHub
parent ac1dc49377
commit 51186bed7c
4 changed files with 124 additions and 10 deletions

View File

@@ -8,11 +8,13 @@ use App\Events\PirepCancelled;
use App\Events\PirepFiled;
use App\Events\PirepRejected;
use App\Events\UserStatsChanged;
use App\Exceptions\AircraftInvalid;
use App\Exceptions\AircraftNotAtAirport;
use App\Exceptions\AircraftPermissionDenied;
use App\Exceptions\PirepCancelNotAllowed;
use App\Exceptions\UserNotAtAirport;
use App\Models\Acars;
use App\Models\Aircraft;
use App\Models\Enums\AcarsType;
use App\Models\Enums\FlightType;
use App\Models\Enums\PirepSource;
@@ -22,6 +24,7 @@ use App\Models\Navdata;
use App\Models\Pirep;
use App\Models\PirepFieldValue;
use App\Models\User;
use App\Repositories\AircraftRepository;
use App\Repositories\PirepRepository;
use Carbon\Carbon;
use function count;
@@ -30,20 +33,24 @@ use Illuminate\Support\Facades\Log;
class PirepService extends Service
{
private $aircraftRepo;
private $geoSvc;
private $userSvc;
private $pirepRepo;
/**
* @param GeoService $geoSvc
* @param PirepRepository $pirepRepo
* @param UserService $userSvc
* @param AircraftRepository $aircraftRepo
* @param GeoService $geoSvc
* @param PirepRepository $pirepRepo
* @param UserService $userSvc
*/
public function __construct(
AircraftRepository $aircraftRepo,
GeoService $geoSvc,
PirepRepository $pirepRepo,
UserService $userSvc
) {
$this->aircraftRepo = $aircraftRepo;
$this->geoSvc = $geoSvc;
$this->userSvc = $userSvc;
$this->pirepRepo = $pirepRepo;
@@ -89,9 +96,14 @@ class PirepService extends Service
}
// See if this aircraft is at the departure airport
/** @var Aircraft $aircraft */
$aircraft = $this->aircraftRepo->findWithoutFail($pirep->aircraft_id);
if ($aircraft === null) {
throw new AircraftInvalid($aircraft);
}
/* @noinspection NotOptimalIfConditionsInspection */
if (setting('pireps.only_aircraft_at_dpt_airport')
&& $pirep->aircraft_id !== $pirep->dpt_airport_id) {
if (setting('pireps.only_aircraft_at_dpt_airport') && $aircraft->airport_id !== $pirep->dpt_airport_id) {
throw new AircraftNotAtAirport($pirep->aircraft);
}