Skip to content

Commit

Permalink
docs: add docs about MapPipe
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Mar 14, 2021
1 parent 6ad92f3 commit 8a8d673
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions docs-site/docs/nestjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,40 @@ export class UserController {
MapInterceptor(destinationModelType, sourceModelType, {
isArray?: boolean;
mapperName?: string;
} & MapAction)
} & MapOptions)
```

> See [MapAction](misc/callbacks.md)
> See [MapOptions](misc/callbacks.md)
## `MapPipe`

`@automapper/nestjs` provides `MapPipe`. When you want to transform the incoming request body before it gets to the route handler, you can utilize `MapPipe` to achieve this behavior

```ts
@Post('/from-body')
postFromBody(@Body(MapPipe(UserDto, User)) user: UserDto) {
// from the request perspective, user coming in as an User object but will be mapped to UserDto with MapPipe
return user;
}
```

`MapPipe` only works with `@Body` or `@Query`.

```ts
@Get('/from-query')
getFromQuery(@Query(MapPipe(UserDto, User)) user: UserDto) {
// from the request perspective, user coming in as an User object but will be mapped to UserDto with MapPipe
return user;
}
```

> Note that when you send a request with `Body` or `Query`, the data is serialized. Data-type like `Date` will come in the request handler as `string`. Hence, please be cautious of the mapping configuration when you use `MapPipe`
`MapPipe` has the same signature as `MapInterceptor`

```ts
MapPipe(destinationModelType, sourceModelType, {
isArray?: boolean;
mapperName?: string;
} & MapOptions)
```

0 comments on commit 8a8d673

Please sign in to comment.