-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (33 loc) · 1.07 KB
/
index.js
File metadata and controls
47 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import axios from 'axios';
const url = 'https://covid19.mathdro.id/api';
export const fetchData = async (country) => {
let changeableUrl = url;
if (country) {
changeableUrl = `${url}/countries/${country}`;
}
try {
const { data: { confirmed, recovered, deaths, lastUpdate } } = await axios.get(changeableUrl);
return { confirmed,recovered,deaths,lastUpdate };
} catch (error) {
console.log(error);
}
}
export const fetchDailyData = async ()=> {
try {
const { data } = await axios.get(`${url}/daily`);
const modifiedData = data.map((dailyData) => ({
confirmed: dailyData.confirmed.total,
deaths: dailyData.deaths.total,
date: dailyData.reportDate
}));
return modifiedData;
} catch (error) {
}
}
export const fetchCountries = async () => {
try {
const { data: { countries } } = await axios.get(`${url}/countries`);
return countries.map((country) => country.name);
} catch (error) {
}
}