-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b63c12d
commit 810bff8
Showing
2 changed files
with
20 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { ValidationPipe } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { TransformInterceptor } from 'src/transform.interceptor'; | ||
import { AppModule } from './app.module'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const app = await NestFactory.create(AppModule); | ||
|
||
app.useGlobalPipes(new ValidationPipe()); | ||
await app.listen(3000); | ||
app.useGlobalPipes(new ValidationPipe()); | ||
app.useGlobalInterceptors(new TransformInterceptor()); | ||
await app.listen(3000); | ||
} | ||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
NestInterceptor, | ||
ExecutionContext, | ||
Injectable, | ||
CallHandler, | ||
} from '@nestjs/common'; | ||
import { classToPlain } from 'class-transformer'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class TransformInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler<any>) { | ||
return next.handle().pipe(map((data) => classToPlain(data))); | ||
} | ||
} |