1- import axios from "axios" ;
21import { generateAsciichart } from "./generateAsciichart" ;
32import { generatePlainOutput } from "./generatePlainOutput" ;
4- import { getAllInfo , getCountryInfo , PlainData } from "./getInformation" ;
3+ import {
4+ getAllInfo ,
5+ getCountryInfo ,
6+ getHistorical ,
7+ PlainData ,
8+ } from "./getInformation" ;
59
610/**
711 * globalHistory shows a tablechart of the cases of all the countries
@@ -11,29 +15,20 @@ import { getAllInfo, getCountryInfo, PlainData } from "./getInformation";
1115 * @param quiet tells the response to be in quiet mode or not
1216 */
1317export const globalHistoryPlain : (
14- mode : string ,
18+ mode : "cases" | "deaths" | "recovered" ,
1519 quiet : boolean
1620) => Promise < string > = async ( mode , quiet ) => {
1721 // Get summary info
1822 const info = ( await getAllInfo ( true ) ) as PlainData ;
1923
2024 // Get data from API
21- const { data : historicalData } = await axios . get ( "/historical/all" ) ;
22- const data : {
23- [ key : string ] : number ;
24- } = historicalData [ mode ] ;
25-
26- // Get first and last date of data
27- const dates = Object . keys ( data ) ;
28- const date = `${
29- mode . charAt ( 0 ) . toUpperCase ( ) + mode . slice ( 1 )
30- } from ${ dates . shift ( ) } to ${ dates . pop ( ) } `;
25+ const historicalData = await getHistorical ( mode ) ;
3126
3227 // Generate historical graph
33- const chart = generateAsciichart ( Object . values ( data ) , true , 7 ) ;
28+ const chart = generateAsciichart ( historicalData . chart , true , 7 ) ;
3429
3530 return generatePlainOutput ( info , `Global Historical Chart` , quiet , [
36- date ,
31+ historicalData . date ,
3732 chart ,
3833 ] ) ;
3934} ;
@@ -49,32 +44,25 @@ export const globalHistoryPlain: (
4944
5045export const historyPerCountryPlain : (
5146 country : string ,
52- mode : string ,
47+ mode : "cases" | "deaths" | "recovered" ,
5348 quiet : boolean
5449) => Promise < string > = async ( country , mode , quiet ) => {
5550 // Get summary info about a country
5651 const info = ( await getCountryInfo ( country , true ) ) as PlainData ;
5752
58- let { data : historicalData } = await axios . get (
59- `/historical/${ info . metainfo . countryName } `
53+ const historicalData = await getHistorical (
54+ mode ,
55+ info . metainfo . countryName as string
6056 ) ;
6157
62- // Get data from API request based on the mode;
63- let data = historicalData [ "timeline" ] [ mode ] ;
64-
65- // Get first and last date of data
66- const dates = Object . keys ( data ) ;
67- // prettier-ignore
68- const date = `${ mode . charAt ( 0 ) . toUpperCase ( ) + mode . slice ( 1 ) } from ${ dates . shift ( ) } to ${ dates . pop ( ) } `
69-
7058 // Generate historical graph
71- const chart = generateAsciichart ( Object . values ( data ) , true , 7 ) ;
59+ const chart = generateAsciichart ( historicalData . chart , true , 7 ) ;
7260
7361 return generatePlainOutput (
7462 info ,
7563 `${ info . metainfo . countryName } Chart` ,
7664 quiet ,
77- [ date , chart ]
65+ [ historicalData . date , chart ]
7866 ) ;
7967} ;
8068
0 commit comments