File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,16 +7,16 @@ class BankAccount {
77 }
88}
99
10- const operations = {
11- Create : ( command , bank ) => {
10+ const OPERATIONS = {
11+ create : ( command , bank ) => {
1212 const account = bank . find ( command . account ) ;
1313 if ( ! account ) bank . createAccount ( command . account ) ;
1414 } ,
15- Withdraw : ( command , bank ) => {
15+ withdraw : ( command , bank ) => {
1616 const account = bank . find ( command . account ) ;
1717 account . balance -= command . amount ;
1818 } ,
19- Income : ( command , bank ) => {
19+ income : ( command , bank ) => {
2020 const account = bank . find ( command . account ) ;
2121 account . balance += command . amount ;
2222 } ,
@@ -37,7 +37,7 @@ class Bank {
3737 }
3838
3939 execute ( command ) {
40- const operation = operations [ command . operation ] ;
40+ const operation = OPERATIONS [ command . operation ] ;
4141 operation ( command , this ) ;
4242 console . dir ( command ) ;
4343 }
Original file line number Diff line number Diff line change @@ -27,8 +27,8 @@ console.table(res1);
2727const marcusBalance1 = readApi1 . getAccount ( marcus ) ;
2828console . dir ( { marcusBalance1 } ) ;
2929
30- const res2 = readApi2 . select ( { account : pius , operation : 'Income ' } ) ;
30+ const res2 = readApi2 . select ( { account : pius , operation : 'income ' } ) ;
3131console . table ( res2 ) ;
3232
33- const res3 = readApi3 . select ( { operation : 'Withdraw ' } ) ;
33+ const res3 = readApi3 . select ( { operation : 'withdraw ' } ) ;
3434console . table ( res3 ) ;
Original file line number Diff line number Diff line change @@ -18,16 +18,17 @@ class BankWrite {
1818 }
1919
2020 createAccount ( account ) {
21- const operation = 'Create ' ;
21+ const operation = 'create ' ;
2222 const command = new AccountCommand ( account , operation ) ;
2323 this . commands . push ( command ) ;
2424 this . eventBus . emit ( 'command' , command ) ;
2525 this . bank . execute ( command ) ;
2626 }
2727
28- operation ( account , amount ) {
29- const operation = amount < 0 ? 'Withdraw' : 'Income' ;
30- const command = new AccountCommand ( account , operation , Math . abs ( amount ) ) ;
28+ operation ( account , value ) {
29+ const operation = value < 0 ? 'withdraw' : 'income' ;
30+ const amount = Math . abs ( value ) ;
31+ const command = new AccountCommand ( account , operation , amount ) ;
3132 this . commands . push ( command ) ;
3233 this . eventBus . emit ( 'command' , command ) ;
3334 this . bank . execute ( command ) ;
You can’t perform that action at this time.
0 commit comments