Skip to content

Commit

Permalink
Merge pull request nestjs#2831 from micalevisk/micalevisk-patch-1
Browse files Browse the repository at this point in the history
docs(pipes): minor searchability improvement for 'zod' usage
  • Loading branch information
kamilmysliwiec authored Aug 23, 2023
2 parents 70a0156 + c6c1961 commit 05d67a4
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions content/pipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,9 @@ In the next section, you'll see how we supply the appropriate schema for a given

```typescript
@@filename()
import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException } from '@nestjs/common';
import { PipeTransform, ArgumentMetadata, BadRequestException } from '@nestjs/common';
import { ZodObject } from 'zod';

@Injectable()
export class ZodValidationPipe implements PipeTransform {
constructor(private schema: ZodObject<any>) {}

Expand All @@ -265,10 +264,9 @@ export class ZodValidationPipe implements PipeTransform {
}
}
@@switch
import { Injectable, BadRequestException } from '@nestjs/common';
import { BadRequestException } from '@nestjs/common';
import { ZodObject } from 'zod';

@Injectable()
export class ZodValidationPip {
constructor(private schema) {}

Expand Down Expand Up @@ -315,7 +313,7 @@ export type CreateCatDto = z.infer<typeof createCatSchema>;
We do that using the `@UsePipes()` decorator as shown below:

```typescript
@@filename()
@@filename(cats.controller)
@Post()
@UsePipes(new ZodValidationPipe(createCatSchema))
async create(@Body() createCatDto: CreateCatDto) {
Expand Down

0 comments on commit 05d67a4

Please sign in to comment.