Add preliminary missing airline check
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Services;
|
||||
use App\DTOs\MissingLivery;
|
||||
use App\Models\IgnoredMissingLivery;
|
||||
use App\Models\UserFlight;
|
||||
use Illuminate\Support\Enumerable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -45,4 +46,36 @@ class AdminService
|
||||
->sortBy('airline_name')
|
||||
->values();
|
||||
}
|
||||
|
||||
function getMissingAirlines(): Enumerable|Collection
|
||||
{
|
||||
$flights = UserFlight::whereNotNull('flight_number')
|
||||
->whereNull('airline_id')
|
||||
->with('user:id,name') // adjust to your actual user relation/columns
|
||||
->get(['id', 'flight_number', 'user_id']);
|
||||
|
||||
return $flights
|
||||
->map(function ($flight) {
|
||||
// Extract the 2-character IATA-style prefix (letters and/or digits)
|
||||
preg_match('/^([A-Za-z0-9]{2})\d+/', trim($flight->flight_number), $matches);
|
||||
|
||||
return [
|
||||
'code' => $matches[1] ?? null,
|
||||
'flight_number' => $flight->flight_number,
|
||||
'link' => "/u/{$flight->user->name}/flight/{$flight->id}",
|
||||
];
|
||||
})
|
||||
->filter(fn ($f) => $f['code'] !== null) // drop any that didn't match the pattern
|
||||
->groupBy('code')
|
||||
->map(function ($group, $code) {
|
||||
return [
|
||||
'code' => $code,
|
||||
'flights' => $group->map(fn ($f) => [
|
||||
'flight_number' => $f['flight_number'],
|
||||
'link' => $f['link'],
|
||||
])->values()->all(),
|
||||
];
|
||||
})
|
||||
->values();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user