11"use strict" ;
22Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
33const constants_1 = require ( "../../constants" ) ;
4+ const extend_metadata_util_1 = require ( "../../utils/extend-metadata.util" ) ;
5+ const shared_utils_1 = require ( "../../utils/shared.utils" ) ;
6+ const validate_each_util_1 = require ( "../../utils/validate-each.util" ) ;
47/**
58 * Binds interceptors to the particular context.
69 * When the `@UseInterceptors()` is used on the controller level:
@@ -9,15 +12,19 @@ const constants_1 = require("../../constants");
912 * When the `@UseInterceptors()` is used on the handle level:
1013 * - Interceptor will be registered only to specified method
1114 *
12- * @param { } ...interceptors (types)
15+ * @param { } ...interceptors
1316 */
1417function UseInterceptors ( ...interceptors ) {
1518 return ( target , key , descriptor ) => {
19+ const isValidInterceptor = interceptor => interceptor &&
20+ ( shared_utils_1 . isFunction ( interceptor ) || shared_utils_1 . isFunction ( interceptor . intercept ) ) ;
1621 if ( descriptor ) {
17- Reflect . defineMetadata ( constants_1 . INTERCEPTORS_METADATA , interceptors , descriptor . value ) ;
22+ validate_each_util_1 . validateEach ( target . constructor , interceptors , isValidInterceptor , '@UseInterceptors' , 'interceptor' ) ;
23+ extend_metadata_util_1 . extendArrayMetadata ( constants_1 . INTERCEPTORS_METADATA , interceptors , descriptor . value ) ;
1824 return descriptor ;
1925 }
20- Reflect . defineMetadata ( constants_1 . INTERCEPTORS_METADATA , interceptors , target ) ;
26+ validate_each_util_1 . validateEach ( target , interceptors , isValidInterceptor , '@UseInterceptors' , 'interceptor' ) ;
27+ extend_metadata_util_1 . extendArrayMetadata ( constants_1 . INTERCEPTORS_METADATA , interceptors , target ) ;
2128 return target ;
2229 } ;
2330}
0 commit comments