Allow nullable field and calculate distance if nulled for flight import #478 (#482)

This commit is contained in:
Nabeel S
2019-12-25 17:16:34 +05:00
committed by GitHub
parent 17637c32d4
commit 4f4d0c266a
3 changed files with 11 additions and 6 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Services\ImportExport;
use App\Contracts\ImportExport;
use App\Models\Airport;
use App\Models\Enums\Days;
use App\Models\Enums\FlightType;
use App\Models\Fare;
@@ -37,7 +36,7 @@ class FlightImporter extends ImportExport
'dpt_time' => 'nullable',
'arr_time' => 'nullable',
'level' => 'nullable|integer',
'distance' => 'required|numeric',
'distance' => 'nullable|numeric',
'flight_time' => 'required|integer',
'flight_type' => 'required|alpha',
'route' => 'nullable',
@@ -109,6 +108,14 @@ class FlightImporter extends ImportExport
// Any specific transformations
// Check/calculate the distance
if (empty($row['distance'])) {
$row['distance'] = $this->airportSvc->calculateDistance(
$row['dpt_airport'],
$row['arr_airport']
);
}
// Check for a valid value
$flight_type = $row['flight_type'];
if (!array_key_exists($flight_type, FlightType::labels())) {