Skip to content

Commit add8ed2

Browse files
style(): minor improvements
1 parent 4ab9b75 commit add8ed2

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

content/pipes.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,17 @@ In the example above, we pass a class (`ParseIntPipe`), not an instance, leaving
6767

6868
```typescript
6969
@Get(':id')
70-
async findOne(@Param('id', new ParseIntPipe({errorHttpStatusCode: HttpStatus.NOT_ACCEPTABLE})) id: number) {
70+
async findOne(
71+
@Param('id', new ParseIntPipe({ errorHttpStatusCode: HttpStatus.NOT_ACCEPTABLE }))
72+
id: number,
73+
) {
7174
return this.catsService.findOne(id);
7275
}
7376
```
7477

75-
Binding the other transformation pipes (all of the **Parse\*** pipes) works similarly. These pipes all work in the context of validating route parameters, querystring parameters and request body values.
78+
Binding the other transformation pipes (all of the **Parse\*** pipes) works similarly. These pipes all work in the context of validating route parameters, query string parameters and request body values.
7679

77-
For example with a querystring parameter:
80+
For example with a query string parameter:
7881

7982
```typescript
8083
@Get()
@@ -83,28 +86,19 @@ async findOne(@Query('id', ParseIntPipe) id: number) {
8386
}
8487
```
8588

86-
With a request body, we use a construct like:
87-
88-
```typescript
89-
@Post()
90-
async update(@Body('id', ParseIntPipe) id: number, @Body('isFriendly', ParseBoolPipe) isFriendly: boolean) {
91-
return this.catsService.update({id, isFriendly});
92-
}
93-
```
94-
9589
Here's an example of using the `ParseUUIDPipe` to parse a string parameter and validate if is a UUID.
9690

9791
```typescript
9892
@@filename()
99-
@Get(':id')
100-
async findOne(@Param('id', new ParseUUIDPipe()) id) {
101-
return this.catsService.findOne(id);
93+
@Get(':uuid')
94+
async findOne(@Param('uuid', new ParseUUIDPipe()) uuid: string) {
95+
return this.catsService.findOne(uuid);
10296
}
10397
@@switch
104-
@Get(':id')
105-
@Bind(Param('id', new ParseUUIDPipe()))
106-
async findOne(id) {
107-
return this.catsService.findOne(id);
98+
@Get(':uuid')
99+
@Bind(Param('uuid', new ParseUUIDPipe()))
100+
async findOne(uuid) {
101+
return this.catsService.findOne(uuid);
108102
}
109103
```
110104

@@ -114,7 +108,7 @@ Above we've seen examples of binding the various `Parse*` family of built-in pip
114108

115109
> info **Hint** Also, see [Validation techniques](/techniques/validation) for extensive examples of validation pipes.
116110
117-
### Custom pipes
111+
#### Custom pipes
118112

119113
As mentioned, you can build your own custom pipes. While Nest provides a robust built-in `ParseIntPipe` and `ValidationPipe`, let's build simple custom versions of each from scratch to see how custom pipes are constructed.
120114

0 commit comments

Comments
 (0)