@@ -43,15 +43,20 @@ class Bank {
4343 const operation = amount < 0 ? 'Withdraw' : 'Income' ;
4444 const execute = operations [ operation ] ;
4545 const command = new AccountCommand (
46- operation , account . name , Math . abs ( amount )
46+ operation ,
47+ account . name ,
48+ Math . abs ( amount ) ,
4749 ) ;
48- const allowed = operations . Allowed ( command ) ;
50+ const check = operations . Allowed ;
51+ const allowed = check ( command ) ;
4952 if ( ! allowed ) {
5053 const target = BankAccount . collection . get ( command . account ) ;
51- throw new Error (
52- 'Command is not allowed:\n' + JSON . stringify ( command ) +
53- '\non ' + JSON . stringify ( target )
54- ) ;
54+ const msg = [
55+ 'Command is not allowed' ,
56+ 'do ' + JSON . stringify ( command ) ,
57+ 'on ' + JSON . stringify ( target ) ,
58+ ] ;
59+ throw new Error ( msg . join ( '\n' ) ) ;
5560 }
5661 this . commands . push ( command ) ;
5762 execute ( command ) ;
@@ -70,7 +75,7 @@ bank.operation(account1, 1000);
7075bank . operation ( account1 , - 50 ) ;
7176const account2 = new BankAccount ( 'Antoninus Pius' ) ;
7277bank . operation ( account2 , 500 ) ;
73- bank . operation ( account2 , - 100 ) ;
78+ bank . operation ( account2 , - 10000 ) ;
7479bank . operation ( account2 , 150 ) ;
7580bank . showOperations ( ) ;
7681console . table ( [ account1 , account2 ] ) ;
0 commit comments