import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from "@nestjs/common"; import { Response } from "express"; import { Observable } from "rxjs"; import { map } from "rxjs/operators"; @Injectable() export class ResponseInterceptor implements NestInterceptor { // intercept(context: ExecutionContext, next: CallHandler>): Observable { const ctx = context.switchToHttp().getResponse(); const statusCode = ctx.statusCode; return next.handle().pipe( map((data) => { if (data && data.data !== undefined) { return { statusCode, success: true, data: data.data, }; } return { statusCode, success: true, data, }; }), ); } }