Skip to content

Instantly share code, notes, and snippets.

@ahmadarif
Last active September 10, 2019 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadarif/2d12018f7467da9203a70d0b2a0341c8 to your computer and use it in GitHub Desktop.
Save ahmadarif/2d12018f7467da9203a70d0b2a0341c8 to your computer and use it in GitHub Desktop.
Nest - TransformInterceptor, working with Exclude decorator
import { ExecutionContext, Injectable, NestInterceptor, CallHandler } from '@nestjs/common';
import { classToPlain } from 'class-transformer';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Injectable()
export class TransformInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(map(data => classToPlain(data)));
}
}
@ahmadarif
Copy link
Author

Add this line to main.ts

app.useGlobalInterceptors(new TransformInterceptor());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment