import axios, { AxiosResponse } from 'axios' import { Status } from '../@types' import { statusApiUri } from '../../app.config' export async function getData(): Promise<{ [key: string]: Status }> { try { const response: AxiosResponse = await axios.get(`${statusApiUri}`) if (!response?.data || response.status !== 200) throw Error('ERROR: no data recieved') // transform data into object with network names as keys let output = Object.fromEntries( response.data?.map((item) => [item.network, item]) ) // make sure 'general' is always the first key output = Object.assign({ general: output['general'] }, output) console.log('Got new data', JSON.stringify(output)) return output } catch (error) { console.error(error.message) } }