Skip to content

Commit

Permalink
Added parseTransactions() module
Browse files Browse the repository at this point in the history
  • Loading branch information
raamSoftwire committed Nov 9, 2017
1 parent be55ed3 commit 1484bc6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 56 deletions.
56 changes: 33 additions & 23 deletions .idea/workspace.xml

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

34 changes: 1 addition & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const Transaction = require('./transactionClass');

const accountExistsQ = require('./accountExistsQ');
const createAccounts = require('./createAccounts');
const parseTransactions = require('./parseTransactions');

const formatter = new Intl.NumberFormat('en-UK', {
style: 'currency',
Expand All @@ -20,40 +21,7 @@ log4js.configure({
categories: {default: { appenders: ['file'], level: 'debug'}}
});

function parseTransactions(){
var keys = Object.keys(records[1]);

for(let i in records)
{
let lineValue = parseInt(i) + 2; // +1 for header row, +1 for zero base

if(!moment(records[i]['Date'],["DD/MM/YYYY","YYYY-MM-DD"],'en').isValid())
{
logger.error("Invalid date found in line " + lineValue +
" : " + records[i]['Date']);
}

else if (isNaN(parseFloat(records[i]['Amount'])))
{
logger.error("Invalid amount found in line " + lineValue
+ " : " + records[i]['Amount'])
}
else
{
transaction = new Transaction(
records[i][keys[0]],
records[i][keys[1]],
records[i][keys[2]],
records[i][keys[3]],
records[i][keys[4]]);

transactions.push(transaction);
//transaction not added to list of transactions
}
}
logger.info("Successfully parsed " + transactions.length + " of " + records.length +
" transactions");
}



Expand Down
42 changes: 42 additions & 0 deletions parseTransactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const log4js = require('log4js');
const moment = require('moment');
const Transaction = require('./transactionClass');

const logger = log4js.getLogger('parseTransactions.js');

function parseTransactions(){
var keys = Object.keys(records[1]);

for(let i in records)
{
let lineValue = parseInt(i) + 2; // +1 for header row, +1 for zero base

if(!moment(records[i]['Date'],["DD/MM/YYYY","YYYY-MM-DD"],'en').isValid())
{
logger.error("Invalid date found in line " + lineValue +
" : " + records[i]['Date']);
}

else if (isNaN(parseFloat(records[i]['Amount'])))
{
logger.error("Invalid amount found in line " + lineValue
+ " : " + records[i]['Amount'])
}
else
{
transaction = new Transaction(
records[i][keys[0]],
records[i][keys[1]],
records[i][keys[2]],
records[i][keys[3]],
records[i][keys[4]]);

transactions.push(transaction);
//transaction not added to list of transactions
}
}
logger.info("Successfully parsed " + transactions.length + " of " + records.length +
" transactions");
}

module.exports = parseTransactions;

0 comments on commit 1484bc6

Please sign in to comment.