-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be55ed3
commit 1484bc6
Showing
3 changed files
with
76 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |