@@ -24,7 +24,9 @@ exports.getCoronaData = async () => {
2424 console . log ( 'cache' , CORONA_ALL_KEY ) ;
2525 return cache ;
2626 }
27- const result = await axios ( 'https://coronavirus-tracker-api.herokuapp.com/all' ) ;
27+ const result = await axios (
28+ 'https://coronavirus-tracker-api.herokuapp.com/all' ,
29+ ) ;
2830
2931 if ( ! result || ! result . data ) {
3032 throw new Error ( 'Source API failure.' ) ;
@@ -47,41 +49,46 @@ exports.getWorldoMetersData = async (countryCode = 'ALL') => {
4749 console . log ( 'cache' , key ) ;
4850 return cache ;
4951 }
50- const result = await axios ( 'https://corona.lmao.ninja/countries?sort=cases' ) ;
52+ const result = await axios (
53+ 'https://corona.lmao.ninja/v2/countries?sort=cases' ,
54+ ) ;
5155 if ( ! result || ! result . data ) {
5256 throw new Error ( 'WorldoMeters Source API failure' ) ;
5357 }
5458
55- const worldStats = result . data . reduce ( ( acc , countryObj ) => {
56- acc . cases += countryObj . cases ;
57- acc . todayCases += countryObj . todayCases ;
58- acc . deaths += countryObj . deaths ;
59- acc . todayDeaths += countryObj . todayDeaths ;
60- acc . recovered += countryObj . recovered ;
61- acc . active += countryObj . active ;
62- acc . critical += countryObj . critical ;
63- return acc ;
64- } , {
65- country : 'World' ,
66- countryCode : 'World' ,
67- cases : 0 ,
68- todayCases : 0 ,
69- deaths : 0 ,
70- todayDeaths : 0 ,
71- recovered : 0 ,
72- active : 0 ,
73- critical : 0 ,
74- } ) ;
59+ const worldStats = result . data . reduce (
60+ ( acc , countryObj ) => {
61+ acc . cases += countryObj . cases ;
62+ acc . todayCases += countryObj . todayCases ;
63+ acc . deaths += countryObj . deaths ;
64+ acc . todayDeaths += countryObj . todayDeaths ;
65+ acc . recovered += countryObj . recovered ;
66+ acc . active += countryObj . active ;
67+ acc . critical += countryObj . critical ;
68+ return acc ;
69+ } ,
70+ {
71+ country : 'World' ,
72+ countryCode : 'World' ,
73+ cases : 0 ,
74+ todayCases : 0 ,
75+ deaths : 0 ,
76+ todayDeaths : 0 ,
77+ recovered : 0 ,
78+ active : 0 ,
79+ critical : 0 ,
80+ } ,
81+ ) ;
7582
76- result . data . forEach ( obj => {
83+ result . data . forEach ( ( obj ) => {
7784 obj . confirmed = obj . cases ;
78- obj . countryCode = obj . countryInfo . iso2 || '' ;
85+ obj . countryCode = obj . countryInfo . iso2 || '' ;
7986 } ) ;
8087 worldStats . casesPerOneMillion = ( worldStats . cases / 7794 ) . toFixed ( 2 ) ;
8188 worldStats . confirmed = worldStats . cases ;
82- let finalData = result . data ;
89+ let finalData = result . data ;
8390 if ( countryCode && countryCode !== 'ALL' ) {
84- finalData = finalData . filter ( obj => obj . countryCode === countryCode ) ;
91+ finalData = finalData . filter ( ( obj ) => obj . countryCode === countryCode ) ;
8592 }
8693 const returnObj = { data : finalData , worldStats } ;
8794
@@ -97,9 +104,24 @@ exports.usaStats = async () => {
97104 console . log ( 'cache' , key ) ;
98105 return cache ;
99106 }
100- const result = await axios ( 'https://corona.lmao.ninja/states' ) ;
107+ const result = await axios ( 'https://corona.lmao.ninja/v2/ states' ) ;
101108 if ( ! result || ! result . data ) {
102109 throw new Error ( 'usa stats API failure' ) ;
103110 }
104111 return result ;
105- } ;
112+ } ;
113+
114+ // exports.bingApi = async (countryCode = 'ALL') => {
115+ // const key = 'bingData';
116+ // const cache = myCache.get(key);
117+
118+ // if (cache) {
119+ // console.log('cache', key);
120+ // return cache;
121+ // }
122+ // const result = await axios('https://bing.com/covid/data');
123+ // if (!result || !result.data) {
124+ // throw new Error('bing api faliure');
125+ // }
126+ // return result;
127+ // };
0 commit comments