-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonFileProcessor.js
38 lines (33 loc) · 1.04 KB
/
jsonFileProcessor.js
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
const moment = require('moment');
class Transaction {
constructor(date, from, to, narrative, amount) {
this.date = date;
this.from = from;
this.to = to;
this.narrative = narrative;
this.amount = amount;
}
}
exports.parseFile = function(data) {
let transfers = parser(data);
parseDates(transfers);
let transactions = getTransactions(transfers);
return transactions;
}
function parser(data) {
return JSON.parse(data);
}
function parseDates(transfers) {
for (let transfer of transfers) {
transfer.Date = moment(transfer.Date).format('DD/MM/YYYY');
// let maybeDate = transfer.Date;
// if (!maybeDate.isValid()) {
// logger.error('Date is in an incorrect format');
// transfer.Date = null;
// }
}
}
function getTransactions(transfers) {
return transfers.map((transfer) => {
return new Transaction(transfer.Date, transfer.FromAccount, transfer.ToAccount, transfer.Narrative, transfer.Amount);
});}