11import axios from "axios" ;
2- import { addFooterAndGenerateChart } from "./addFooterAndGenerateChart " ;
2+ import { generateOutput } from "./generateOutput " ;
33import { generateAsciichart } from "./generateAsciichart" ;
44
55axios . defaults . baseURL = "https://disease.sh/v3/covid-19" ;
@@ -85,11 +85,13 @@ const getCountryInfo: (
8585 * Today Cases, Today Deaths, Critical, Mortality %, Recovery in a chart
8686 * @param country country code or country name that the user wants to query
8787 * @param mode Mode that the user wants to query must be: "cases" | "deaths" | "recoveries"
88+ * @param quiet tells the response to be in quiet mode or not
8889 */
8990export const historyPerCountry : (
9091 country : string ,
91- mode : "cases" | "deaths" | "recovered"
92- ) => Promise < string > = async ( country , mode ) => {
92+ mode : "cases" | "deaths" | "recovered" ,
93+ quiet : boolean
94+ ) => Promise < string > = async ( country , mode , quiet ) => {
9395 // Get summary info about a country
9496 let [ updated , apiCountryname , countryName , rows ] = await getCountryInfo (
9597 country
@@ -114,10 +116,11 @@ export const historyPerCountry: (
114116 rows = rows . concat ( chart ) ;
115117
116118 // generate table
117- let response = addFooterAndGenerateChart (
119+ let response = generateOutput (
118120 `${ countryName } Historical Chart` ,
119121 updated ,
120- rows
122+ rows ,
123+ quiet
121124 ) ;
122125
123126 return response ;
@@ -127,10 +130,13 @@ export const historyPerCountry: (
127130 * globalHistory shows a tablechart of the cases of all the countries
128131 * Shows Cases, Deaths, Recovered, Active, Cases/Million
129132 * and a graph of a country's cases
133+ * @param mode Mode that the user wants to query must be: "cases" | "deaths" | "recoveries"
134+ * @param quiet tells the response to be in quiet mode or not
130135 */
131136export const globalHistory : (
132- mode : "cases" | "deaths" | "recovered"
133- ) => Promise < string > = async ( mode ) => {
137+ mode : "cases" | "deaths" | "recovered" ,
138+ quiet : boolean
139+ ) => Promise < string > = async ( mode , quiet ) => {
134140 // Get summary info
135141 let [ updated , rows ] = await getAllInfo ( ) ;
136142
@@ -150,10 +156,11 @@ export const globalHistory: (
150156 rows . push ( `${ mode . charAt ( 0 ) . toUpperCase ( ) + mode . slice ( 1 ) } from ${ firstDate } to ${ lastDate } ` . magenta )
151157 rows = rows . concat ( chart ) ;
152158
153- let response = addFooterAndGenerateChart (
159+ let response = generateOutput (
154160 "Global Historical Chart" ,
155161 updated ,
156- rows
162+ rows ,
163+ quiet
157164 ) ;
158165
159166 return response ;
@@ -164,16 +171,19 @@ export const globalHistory: (
164171 * Shows Cases, Deaths, Recovered, Active, Cases/Million
165172 * Today Cases, Today Deaths, Critical, Mortality %, Recovery in a chart
166173 * @param country country code or country name that the user wants to query
174+ * @param quiet tells the response to be in quiet mode or not
167175 */
168176export const informationPerCountry : (
169- country : string
170- ) => Promise < string > = async ( country ) => {
177+ country : string ,
178+ quiet : boolean
179+ ) => Promise < string > = async ( country , quiet ) => {
171180 let [ updated , _ , countryName , rows ] = await getCountryInfo ( country ) ;
172181
173- let response = addFooterAndGenerateChart (
182+ let response = generateOutput (
174183 `${ countryName } Update` ,
175184 updated ,
176- rows
185+ rows ,
186+ quiet
177187 ) ;
178188
179189 // return response;
@@ -183,15 +193,14 @@ export const informationPerCountry: (
183193/**
184194 * globalInformation tracks the info of all countries
185195 * Shows Cases, Deaths, Recovered, Mortality %, Recovered% in a chart
196+ * @param quiet tells the response to be in quiet mode or not
186197 */
187- export const globalInformation : ( ) => Promise < string > = async ( ) => {
198+ export const globalInformation : ( quiet : boolean ) => Promise < string > = async (
199+ quiet
200+ ) => {
188201 const [ updated , rowsOfData ] = await getAllInfo ( ) ;
189202
190- let response = addFooterAndGenerateChart (
191- "Global Update" ,
192- updated ,
193- rowsOfData
194- ) ;
203+ let response = generateOutput ( "Global Update" , updated , rowsOfData , quiet ) ;
195204
196205 return response ;
197206} ;
0 commit comments