-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.js
More file actions
59 lines (49 loc) · 1.99 KB
/
program.js
File metadata and controls
59 lines (49 loc) · 1.99 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
48
49
50
51
52
53
54
55
56
57
58
59
const {Bank, Transaction, Account} = require('./classes.js')
const fs = require('fs');
const ps = require('prompt-sync');
const log4js = require('log4js');
const moment = require('moment');
const {importFile, exportFile, listAll, listAccountTransactions} = require('./commands')
const {checkTransactions} = require("./errorHandling");
const {exportXmlFile} = require("./exportXmlFile");
const {exportCsvFile} = require("./exportCsvFile");
const prompt = ps();
const logger = log4js.getLogger('program.js');
log4js.configure({
appenders: {
file: {type: 'fileSync', filename: 'logs/debug.log'}
},
categories: {
default: {appenders: ['file'], level: 'debug'}
}
});
const runProgram = () => {
while (true) {
const userFile = prompt("Please enter a file name:")
const transactions = importFile(userFile);
checkTransactions(transactions);
const userCommand = prompt("Please enter a command:")
if (userCommand.match(/list all/ig)) {
listAll(transactions);
} else if (userCommand.match(/List.*/ig)) {
try {
listAccountTransactions(transactions, userCommand.substring(5));
const exportChoice = prompt("Would you like to export your transactions? (Y/N)", "", {})
if(exportChoice === 'Y') {
const exportFormat = prompt("Please enter an export format(csv/json/xml)");
const exportTransactions = listAccountTransactions(transactions, userCommand.substring(5));
exportFile(exportFormat, exportTransactions);
} else {
return
}
} catch {
logger.error(`Unable to process file. Please review`)
return
}
} else {
console.log(`${userCommand} is not a recognised command. Please try again`)
return
}
};
}
runProgram();