@@ -20,6 +20,8 @@ class AccountQuery {
2020}
2121
2222class BankAccount {
23+ static collection = new Map ( ) ;
24+
2325 constructor ( name ) {
2426 this . name = name ;
2527 this . balance = 0 ;
@@ -31,14 +33,12 @@ class BankAccount {
3133 }
3234}
3335
34- BankAccount . collection = new Map ( ) ;
35-
36- const operations = {
37- Withdraw : ( command ) => {
36+ const OPERATIONS = {
37+ withdraw : ( command ) => {
3838 const account = BankAccount . find ( command . account ) ;
3939 account . balance -= command . amount ;
4040 } ,
41- Income : ( command ) => {
41+ income : ( command ) => {
4242 const account = BankAccount . find ( command . account ) ;
4343 account . balance += command . amount ;
4444 } ,
@@ -49,12 +49,11 @@ class BankWrite {
4949 this . commands = [ ] ;
5050 }
5151
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 ) ;
5857 this . commands . push ( command ) ;
5958 eventBus . emit ( 'command' , command ) ;
6059 console . dir ( command ) ;
@@ -106,11 +105,13 @@ console.table([account1, account2]);
106105const res1 = readApi1 . select ( { account : 'Marcus Aurelius' } ) ;
107106console . table ( res1 ) ;
108107
109- const res2 = readApi2
110- . select ( { account : 'Antoninus Pius' , operation : 'Income' } ) ;
108+ const res2 = readApi2 . select ( {
109+ account : 'Antoninus Pius' ,
110+ operation : 'income' ,
111+ } ) ;
111112console . table ( res2 ) ;
112113
113- const res3 = readApi3 . select ( { operation : 'Withdraw ' } ) ;
114+ const res3 = readApi3 . select ( { operation : 'withdraw ' } ) ;
114115console . table ( res3 ) ;
115116
116117console . table ( readApi3 . queries ) ;
0 commit comments