Spaces:
Paused
Paused
Download apps/prevision-api/src/common/interceptors/response.interceptor.ts from modventures/prevision: direct link, hf CLI and curl.
- Browser
- Download file 865 Bytes
-
https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/common/interceptors/response.interceptor.ts
- Command line
-
hf download hf://spaces/modventures/prevision/apps/prevision-api/src/common/interceptors/response.interceptor.ts
-
curl -L -o response.interceptor.ts https://huggingface.co/spaces/modventures/prevision/resolve/main/apps/prevision-api/src/common/interceptors/response.interceptor.ts
865 Bytes
| import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; | |
| import { map, type Observable } from 'rxjs'; | |
| import { Paginated } from '../dto/paginated.dto.js'; | |
| import type { ApiSuccess } from '../interfaces/api-response.interface.js'; | |
| /** Every successful response becomes `{ success: true, data, meta? }`; empty (204) responses stay empty. */ | |
| () | |
| export class ResponseInterceptor<T> implements NestInterceptor<T, ApiSuccess<unknown> | undefined> { | |
| intercept(_: ExecutionContext, next: CallHandler<T>): Observable<ApiSuccess<unknown> | undefined> { | |
| return next.handle().pipe( | |
| map((body) => { | |
| if (body === undefined) return undefined; | |
| if (body instanceof Paginated) return { success: true, data: body.items, meta: body.meta }; | |
| return { success: true, data: body }; | |
| }), | |
| ); | |
| } | |
| } | |