Extract ui api requests to common functions

This commit is contained in:
2023-09-17 09:35:03 -04:00
parent 4a3225c3f9
commit 5443ed6d77
6 changed files with 43 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
import axios from 'axios';
import { Airport } from './airport.types';
import { Metar } from './metar.types';
import { getRequest } from '.';
interface GetMetarsResponse {
data: Metar[];
@@ -11,7 +11,6 @@ export async function getMetars(airports: Airport[]): Promise<GetMetarsResponse>
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));
const response = await getRequest(`metars/${stationICAOs}`, {});
return response?.data || { data: [] };
}