| 123456789101112131415161718192021222324252627282930 |
- 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<unknown> | StreamableFile => {
- if (data instanceof StreamableFile) {
- return data;
- }
- return {
- error: '',
- status: 1,
- code: 'OK',
- data,
- timestamp: new Date().toISOString(),
- };
- }),
- );
- }
- }
|