@@ -20,6 +20,8 @@ class AccountQuery {
20
20
}
21
21
22
22
class BankAccount {
23
+ static collection = new Map ( ) ;
24
+
23
25
constructor ( name ) {
24
26
this . name = name ;
25
27
this . balance = 0 ;
@@ -31,14 +33,12 @@ class BankAccount {
31
33
}
32
34
}
33
35
34
- BankAccount . collection = new Map ( ) ;
35
-
36
- const operations = {
37
- Withdraw : ( command ) => {
36
+ const OPERATIONS = {
37
+ withdraw : ( command ) => {
38
38
const account = BankAccount . find ( command . account ) ;
39
39
account . balance -= command . amount ;
40
40
} ,
41
- Income : ( command ) => {
41
+ income : ( command ) => {
42
42
const account = BankAccount . find ( command . account ) ;
43
43
account . balance += command . amount ;
44
44
} ,
@@ -49,12 +49,11 @@ class BankWrite {
49
49
this . commands = [ ] ;
50
50
}
51
51
52
- operation ( account , amount ) {
53
- const operation = amount < 0 ? 'Withdraw' : 'Income' ;
54
- const execute = operations [ operation ] ;
55
- const command = new AccountCommand (
56
- account . name , operation , Math . abs ( amount )
57
- ) ;
52
+ operation ( account , value ) {
53
+ const operation = value < 0 ? 'withdraw' : 'income' ;
54
+ const execute = OPERATIONS [ operation ] ;
55
+ const amount = Math . abs ( value ) ;
56
+ const command = new AccountCommand ( account . name , operation , amount ) ;
58
57
this . commands . push ( command ) ;
59
58
eventBus . emit ( 'command' , command ) ;
60
59
console . dir ( command ) ;
@@ -106,11 +105,13 @@ console.table([account1, account2]);
106
105
const res1 = readApi1 . select ( { account : 'Marcus Aurelius' } ) ;
107
106
console . table ( res1 ) ;
108
107
109
- const res2 = readApi2
110
- . select ( { account : 'Antoninus Pius' , operation : 'Income' } ) ;
108
+ const res2 = readApi2 . select ( {
109
+ account : 'Antoninus Pius' ,
110
+ operation : 'income' ,
111
+ } ) ;
111
112
console . table ( res2 ) ;
112
113
113
- const res3 = readApi3 . select ( { operation : 'Withdraw ' } ) ;
114
+ const res3 = readApi3 . select ( { operation : 'withdraw ' } ) ;
114
115
console . table ( res3 ) ;
115
116
116
117
console . table ( readApi3 . queries ) ;
0 commit comments