Skip to content

Commit

Permalink
Updated absolute filepaths to relate filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
raamSoftwire committed Nov 9, 2017
1 parent 70b780f commit be55ed3
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 59 deletions.
83 changes: 64 additions & 19 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions createAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Account = require('./accountClass');
const accountExistsQ = require('./accountExistsQ');

function createAccounts()
{
for(let i in transactions)
{
if(!accountExistsQ(transactions[i].from))
{
//if the account does not exist,create the account
senderAccount = new Account(transactions[i].from,0);
accounts.push(senderAccount);
}
else
{
senderAccount = accounts.find(account => account.name === transactions[i].from);
}

if(!accountExistsQ(transactions[i].to))
{
//if the account does not exist,create the account
receiverAccount = new Account(transactions[i].to,0);
accounts.push(receiverAccount);
}
else
{
receiverAccount = accounts.find(account => account.name === transactions[i].to);
}

senderAccount.amount = senderAccount.amount - transactions[i].amount;
receiverAccount.amount = receiverAccount.amount + transactions[i].amount;
}
}

module.exports = createAccounts;
49 changes: 9 additions & 40 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const readlineSync = require('readline-sync');
const log4js = require('log4js');
const moment = require('moment');

const Transaction = require('C:\\Work\\Training\\SupportBank\\transactionClass.js');
const Account = require('C:\\Work\\Training\\SupportBank\\accountClass.js');
const Transaction = require('./transactionClass');

const accountExistsQ = require('C:\\Work\\Training\\SupportBank\\accountExistsQ.js');
const accountExistsQ = require('./accountExistsQ');
const createAccounts = require('./createAccounts');

const formatter = new Intl.NumberFormat('en-UK', {
style: 'currency',
Expand Down Expand Up @@ -55,36 +55,7 @@ function parseTransactions(){
" transactions");
}

function createAccounts()
{
for(let i in transactions)
{
if(!accountExistsQ(transactions[i].from))
{
//if the account does not exist,create the account
senderAccount = new Account(transactions[i].from,0);
accounts.push(senderAccount);
}
else
{
senderAccount = accounts.find(account => account.name === transactions[i].from);
}

if(!accountExistsQ(transactions[i].to))
{
//if the account does not exist,create the account
receiverAccount = new Account(transactions[i].to,0);
accounts.push(receiverAccount);
}
else
{
receiverAccount = accounts.find(account => account.name === transactions[i].to);
}

senderAccount.amount = senderAccount.amount - transactions[i].amount;
receiverAccount.amount = receiverAccount.amount + transactions[i].amount;
}
}

function importFile(fileName) {
var ext = fileName.split('.').pop();
Expand All @@ -93,6 +64,11 @@ function importFile(fileName) {
try {
const inputArray = fs.readFileSync(dataFile).toString();
const records = parse(inputArray, {columns: true});
// return records.map(function(record) {
//
// return new Transaction(record.date);
// });

return records;
}

Expand Down Expand Up @@ -131,7 +107,7 @@ records = importFile(dataFile);



const logger = log4js.getLogger(dataFile);
const logger = log4js.getLogger('index.js');
logger.debug("Program starting up...")


Expand All @@ -141,13 +117,6 @@ parseTransactions();
accounts = [];
createAccounts();








const userInput = readlineSync.question('Please enter "List All" or "List [Account]" : ');
const pattern = new RegExp("List ");

Expand Down

0 comments on commit be55ed3

Please sign in to comment.