import { CallHandler, ExecutionContext, Injectable, NestInterceptor, StreamableFile, } from '@nestjs/common'; import { map } from 'rxjs/operators'; import { ApiResponse } from '../interfaces/api-response.interface'; @Injectable() export class ResponseInterceptor implements NestInterceptor { intercept(_context: ExecutionContext, next: CallHandler) { return next.handle().pipe( map((data): ApiResponse | StreamableFile => { if (data instanceof StreamableFile) { return data; } return { error: '', status: 1, code: 'OK', data, timestamp: new Date().toISOString(), }; }), ); } }