Refactor, fixed search
This commit is contained in:
17
weather-ui/src/app/_api/metar.ts
Normal file
17
weather-ui/src/app/_api/metar.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import axios from 'axios';
|
||||
import { Airport } from './airport.types';
|
||||
import { Metar } from './metar.types';
|
||||
|
||||
interface GetMetarsResponse {
|
||||
data: Metar[];
|
||||
}
|
||||
|
||||
export async function getMetars(airports: Airport[]): Promise<GetMetarsResponse> {
|
||||
if (airports.length == 0) {
|
||||
return { data: [] };
|
||||
}
|
||||
const stationICAOs: string = airports.map((airport) => airport.icao).join(',');
|
||||
const url = `http://localhost:5000/metars/${stationICAOs}`;
|
||||
const response = await axios.get(url).catch((error) => console.error(error));
|
||||
return response?.data || { data: [] };
|
||||
}
|
||||
Reference in New Issue
Block a user