diff --git a/SoftBankNew.ts b/SoftBankNew.ts index 71c958d..8320767 100644 --- a/SoftBankNew.ts +++ b/SoftBankNew.ts @@ -1,99 +1,118 @@ -interface Account { // Interface for each person's account - net :number; +var readlineSync = require('readline-sync') +var winston = require('winston'); +var lines = require('./Transactions2013.json'); + +// LOGGING: + +winston.level = 'debug'; +winston.add(winston.transports.File, {filename: 'SoftBankNew2Problems.log' }); +winston.remove(winston.transports.Console); + +// ITNERFACES: + +// Interface for each person's account +interface Account { + balance :number; transactions :Transaction[]; } -interface Transaction { // Interface for all the transactions of each person. - credit :boolean; - amount :number +// Interface for all the transactions of each person. +interface Transaction { + from :string; //Other person involved in the transaction + to: string; + amount :number; date :string; narrative :string; } -var peopleAccounts = {} // Dictionary of people, with their names as the keys to access their accounts +// METHODS: -// Input the file and parse it into an array of lines: -var fs = require('fs'); -var text = fs.readFileSync('Transactions2014.csv','utf8',(err,data) => { - if err throw err; - return data; -}) -var lines = text.split('\r\n'); - -// Process each line to produce all the accounts and update their transactions accordingly -var len = lines.length; -for (var i=1; i { - switch(command) { +// Offers command line input for the program +function commandLineInstructions() :void { + while (command != 'Quit') { + var command = readlineSync.question("Enter a command. 'List_All' to show everyone's balances. 'List_Person' to list the transactions of a person, chosen later through a menu. 'Quit' to quit: "); + console.log('You command was: ' + command); + switch (command) { case 'List_All': printPeopleBalances(); - console.log("Printed"); + console.log('Done!'); break; case 'List_Person': - rl.question('Whose account do you wish to see?', (name) => { - printPersonsTransactions(name); - }); + var personName = readlineSync.question('Whose Account do you wish to see: '); + printPersonsTransactions(personName); + console.log('Done!'); + break; + case 'Quit': + console.log('Quit successful'); break; default: + console.log('Sorry, invalid input. Please try again.'); } - prompting(); - }); -} + } +}; + +// Runs the program +function run() :void { + for (var i=1; i