-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransactionClass.js
More file actions
72 lines (47 loc) · 1.48 KB
/
transactionClass.js
File metadata and controls
72 lines (47 loc) · 1.48 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var moment = require('moment');
const log4js = require('log4js');
const logger = log4js.getLogger('transactionClass.js');
class Transaction {
constructor(date, from, to, narrative, amount) {
this.date = date;
this.from = from;
this.to = to;
this.narrative = narrative;
this.amount = amount;
}
// constructor(date, from, to, narrative, amount) {
// this.date = moment(date,["DD/MM/YYYY","YYYY-MM-DD"],'en').format("DD/MM/YYYY");
// this.from = from;
// this.to = to;
// this.narrative = narrative;
// this.amount = parseFloat(amount);
// }
isValidTransaction() {
let validity = true;
if(!moment(this.date,["DD/MM/YYYY","YYYY-MM-DD"],'en').isValid())
{
logger.error("Invalid date found in line X : " + this.date);
validity = false;
}
if (isNaN(parseFloat(this.amount)))
{
logger.error("Invalid amount found in line X : " + this.amount);
validity = false;
}
return validity;
}
processTransaction(){
if(this.isValidTransaction())
{
this.date = moment(date,["DD/MM/YYYY","YYYY-MM-DD"],'en').format("DD/MM/YYYY");
this.amount = parseFloat(amount);
}
else
{
// skip this transaction
//log something
console.log("Bad transaction");
}
}
}
module.exports = Transaction;