-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
107 lines (87 loc) · 3.06 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const cliProgram = require("commander");
const oilService = require("./src/services/oil");
const fs = require("fs");
cliProgram
.version("v1.0.0")
.name("oil-data-utils")
.description("Oil Data functionalities");
//fetching data
cliProgram
.command('fetch-oil-data-from-server')
.alias('fetch-oil-data')
.option('--count <count>', 'No. of rows to display')
.description('Fetch the latest data from the oli service provider')
.action(async (program) => {
const oilData = await oilService.getOilData();
for(i=0; i<program.count; i++) {
console.log(oilData[i]);
}
});
//store data into a file
cliProgram
.command('store-oil-data-to-file')
.alias('store-oil-data-in-file')
.option('--filename <filename>', 'Name of file')
.description('Store the latest data from the oil service provider')
.action(async (program) => {
const { filename } = program;
const oilData = await oilService.getOilData();
fs.writeFileSync(filename, JSON.stringify(oilData), 'utf-8');
console.log(`Data saved in file named ${filename}`);
});
//store oil data in database
cliProgram
.command('store-oil-data-to-database')
.alias('store-oil-data')
.option('--tablename <tablename>', 'Name of table in database')
.description('Store the latest data from the oil service provider')
.action(async (program) => {
const { tablename } = program;
const oilData = await oilService.getOilData();
console.log(oilData);
await oilService.storeOilData(oilData, tablename);
console.log(`Data stored in database - ${tablename}`);
});
//view all data
cliProgram
.command('view-oil-data-from-database')
.alias('view-oil-data')
.option('--tablename <tablename>', 'Name of table in datbaase')
.description('View all data from the oil service provider')
// .parse(process.argv)
.action(async (program) => {
const { tablename } = program;
const oilData = await oilService.viewOilData();
console.log(oilData);
await oilService.viewOilData(oilData, tablename);
console.log(`All Data form database - ${tablename}`);
});
//view avg sale of each product by country
cliProgram
.command('view-oil-data-avg-from-database')
.alias('view-oil-data-avg')
.option('--tablename <tablename>', 'Name of table in datbaase')
.description('View avg data from the oil service provider')
// .parse(process.argv)
.action(async (program) => {
const { tablename } = program;
const oilData = await oilService.viewOilDataAvg();
console.log(oilData);
await oilService.viewOilDataAvg(oilData, tablename);
console.log(`All Data form database - ${tablename}`);
});
//view min sale of each product by country
cliProgram
.command('view-oil-data-min-from-database')
.alias('view-oil-data-min')
.option('--tablename <tablename>', 'Name of table in datbaase')
.description('View min sale year for a product from the oil service provider')
// .parse(process.argv)
.action(async (program) => {
const { tablename } = program;
const oilData = await oilService.viewOilDataMin();
console.log(oilData);
await oilService.viewOilDataMin(oilData, tablename);
console.log(`All Data form database - ${tablename}`);
});
cliProgram.parse(process.argv);