File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ interface IPaymentAPI {
2+ getPaymenyDetail ( id : number ) : IPaymentDetail | undefined ;
3+ }
4+
5+ interface IPaymentDetail {
6+ id : number ;
7+ sum : number ;
8+ }
9+
10+ class PaymentAPI implements IPaymentAPI {
11+ private data = [ { id : 1 , sum : 1000 } ]
12+ getPaymenyDetail ( id : number ) : IPaymentDetail | undefined {
13+ return this . data . find ( d => d . id === id )
14+ }
15+ }
16+
17+ class PaymentAccessProxy implements IPaymentAPI {
18+ constructor ( private api : PaymentAPI , private userId : number ) { }
19+
20+ getPaymenyDetail ( id : number ) : IPaymentDetail | undefined {
21+ if ( this . userId === 1 ) {
22+ return this . api . getPaymenyDetail ( id )
23+ }
24+ console . log ( 'Попытка получить данные платежа' )
25+ return undefined
26+ }
27+ }
28+
29+ const proxy = new PaymentAccessProxy ( new PaymentAPI ( ) , 1 )
30+ console . log ( proxy . getPaymenyDetail ( 1 ) )
31+
32+ const proxy2 = new PaymentAccessProxy ( new PaymentAPI ( ) , 2 )
33+ console . log ( proxy . getPaymenyDetail ( 2 ) )
You can’t perform that action at this time.
0 commit comments