-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTransaction.js
86 lines (66 loc) · 1.54 KB
/
Transaction.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var {
TRANSACTION,
EXPENSE_TYPE_EQUAL,
EXPENSE_TYPE_PERCENT,
EXPENSE_TYPE_EXACT
} = require('./constant')
class Transaction {
#id
#payer_id
#expense_type
#amount
#payee
constructor() {
this.#id = TRANSACTION++
}
get ID() {
return this.#id
}
get PayerId() {
return this.#payer_id
}
get ExpenseType() {
return this.#expense_type
}
get Amount() {
return this.#amount
}
get Payee() {
return this.#payee
}
set PayerId(payer_id) {
if(payer_id === "" || payer_id === undefined) {
throw "invalid user id"
}
this.#payer_id = payer_id
}
set ExpenseType(expense_type) {
if(expense_type != EXPENSE_TYPE_EQUAL &&
expense_type != EXPENSE_TYPE_EXACT &&
expense_type != EXPENSE_TYPE_PERCENT) {
throw "Invalid expense type"
}
this.#expense_type = expense_type
}
set Amount(amount) {
if(amount < 0) {
throw "Invalid amount"
}
this.#amount = amount
}
set Payee(payee) {
if(!Array.isArray(payee)) {
throw "Payee must be an array"
}
this.#payee = payee
}
static createTransaction(payer_id, expense_type, amount, payee) {
var t = new Transaction()
t.PayerId = payer_id
t.ExpenseType = expense_type
t.Amount = amount
t.Payee = payee
return t
}
}
module.exports.Transaction = Transaction