File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -249,34 +249,33 @@ In the next section, you'll see how we supply the appropriate schema for a given
249
249
``` typescript
250
250
@@filename ()
251
251
import { PipeTransform , ArgumentMetadata , BadRequestException } from ' @nestjs/common' ;
252
- import { ZodObject } from ' zod' ;
252
+ import { ZodSchema } from ' zod' ;
253
253
254
254
export class ZodValidationPipe implements PipeTransform {
255
- constructor (private schema : ZodObject < any > ) {}
255
+ constructor (private schema : ZodSchema ) {}
256
256
257
257
transform(value : unknown , metadata : ArgumentMetadata ) {
258
258
try {
259
- this .schema .parse (value );
259
+ const parsedValue = this .schema .parse (value );
260
+ return parsedValue ;
260
261
} catch (error ) {
261
262
throw new BadRequestException (' Validation failed' );
262
263
}
263
- return value ;
264
264
}
265
265
}
266
266
@@switch
267
267
import { BadRequestException } from ' @nestjs/common' ;
268
- import { ZodObject } from ' zod' ;
269
268
270
- export class ZodValidationPip {
269
+ export class ZodValidationPipe {
271
270
constructor (private schema ) {}
272
271
273
272
transform(value , metadata ) {
274
273
try {
275
- this .schema .parse (value );
274
+ const parsedValue = this .schema .parse (value );
275
+ return parsedValue ;
276
276
} catch (error ) {
277
277
throw new BadRequestException (' Validation failed' );
278
278
}
279
- return value ;
280
279
}
281
280
}
282
281
You can’t perform that action at this time.
0 commit comments