@@ -10,10 +10,12 @@ import {
1010 UseInterceptors ,
1111 UseGuards ,
1212 Scope ,
13- Inject
13+ ValidationPipe
1414} from "@nestjs/common" ;
1515import { Ctx } from "@nestjs/microservices" ;
1616
17+ import { IsNotEmpty } from "class-validator" ;
18+
1719import { CodedRpcException , JsonRpcContext , RpcController , RpcMethod , RpcService } from "." ;
1820
1921const initialModuleState = {
@@ -83,6 +85,11 @@ class TestGuard implements CanActivate {
8385
8486type IRpcTestService = RpcController < ITestClientService > ;
8587
88+ export class TestDto {
89+ @IsNotEmpty ( )
90+ test ! : string ;
91+ }
92+
8693@RpcService ( {
8794 namespace : "test"
8895} )
@@ -92,14 +99,6 @@ export class TestService implements IRpcTestService {
9299 DecorationsState . serviceConstructorCount = DecorationsState . serviceConstructorCount + 1 ;
93100 }
94101
95- @UsePipes ( TestPipe )
96- @UseInterceptors ( TestInterceptor )
97- @UseGuards ( TestGuard )
98- @RpcMethod ( )
99- public async invoke ( params : { test : string } ) {
100- return Promise . resolve ( params ) ;
101- }
102-
103102 @UsePipes ( TestPipe )
104103 @UseInterceptors ( TestInterceptor )
105104 @UseGuards ( TestGuard )
@@ -110,10 +109,11 @@ export class TestService implements IRpcTestService {
110109 }
111110
112111 @UsePipes ( TestPipe )
112+ @UsePipes ( ValidationPipe )
113113 @UseInterceptors ( TestInterceptor )
114114 @UseGuards ( TestGuard )
115115 @RpcMethod ( )
116- public async invokeClientService ( params : { test : string } ) {
116+ public async invokeClientService ( params : TestDto ) {
117117 return Promise . resolve ( params ) ;
118118 }
119119
@@ -131,7 +131,6 @@ export class TestService implements IRpcTestService {
131131}
132132
133133export interface ITestClientService {
134- invoke ( params : { test : string } ) : Promise < { test : string } > ;
135134 invokeClientService ( params : { test : string } ) : Promise < { test : string } > ;
136135 testError ( params : { errorTest : string } ) : Promise < void > ;
137136 injectContext ( params : { } ) : Promise < { key : string | undefined } > ;
0 commit comments