-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUserTransaction.js
83 lines (63 loc) · 1.64 KB
/
UserTransaction.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
var {
USER_TRANSACTION,
TRANSACTION_TYPE_CREDIT,
TRANSACTION_TYPE_DEBIT
} = require('./constant')
class UserTransaction {
#id
#user_id
#transaction_type
#transaction_id
#amount
constructor() {
this.#id = USER_TRANSACTION ++
}
get ID() {
return this.#id
}
get UserId() {
return this.#user_id
}
get TransactionType() {
return this.#transaction_type
}
get TransactionId() {
return this.#transaction_id
}
get Amount() {
return this.#amount
}
set UserId(user_id) {
if(user_id === "" || user_id === undefined) {
throw "Invalid user id"
}
this.#user_id = user_id
}
set TransactionType(transaction_type) {
if(transaction_type != TRANSACTION_TYPE_CREDIT && transaction_type != TRANSACTION_TYPE_DEBIT) {
throw "Invalid transaction type"
}
this.#transaction_type = transaction_type
}
set TransactionId(transaction_id) {
if(transaction_id === "" || transaction_id === undefined) {
throw "Invalid transaction_id"
}
this.#transaction_id = transaction_id
}
set Amount(amount) {
if(amount < 0) {
throw "Invalid amount"
}
this.#amount = amount
}
static createUserTransaction(tran_id, user_id, tran_type, amount) {
var ut = new UserTransaction()
ut.Amount = amount
ut.UserId = user_id
ut.TransactionId = tran_id
ut.TransactionType = tran_type
return ut
}
}
module.exports.UserTransaction = UserTransaction