mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 13:01:10 +10:00
switch to nx monorepo
This commit is contained in:
27
apps/server/src/interceptors/http-response.interceptor.ts
Normal file
27
apps/server/src/interceptors/http-response.interceptor.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {
|
||||
CallHandler,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
NestInterceptor,
|
||||
} from '@nestjs/common';
|
||||
import { map, Observable } from 'rxjs';
|
||||
export interface Response<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TransformHttpResponseInterceptor<T>
|
||||
implements NestInterceptor<T, Response<T>>
|
||||
{
|
||||
intercept(
|
||||
context: ExecutionContext,
|
||||
next: CallHandler<T>,
|
||||
): Observable<Response<T>> {
|
||||
return next.handle().pipe(
|
||||
map((data) => {
|
||||
const status = context.switchToHttp().getResponse().statusCode;
|
||||
return { data, success: true, status };
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user