Advertisement
nodejsdeveloperskh

serializer-output-dto-nest-interceptor-rxjs

Jan 30th, 2022
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {CallHandler, ExecutionContext, Injectable, NestInterceptor,} from '@nestjs/common';
  2. import {map, Observable} from 'rxjs';
  3.  
  4. @Injectable()
  5. export class TestInterceptor implements NestInterceptor {
  6.     intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
  7.         // add logic before handler
  8.  
  9.         // response RxJs (observable)
  10.         return next.handle().pipe(
  11.             map((value) => {
  12.  
  13.                 return {
  14.                     error: false,
  15.                     data: value
  16.                 };
  17.             }),
  18.         );
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement