mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-10-14 05:19:19 +00:00
30 lines
572 B
TypeScript
30 lines
572 B
TypeScript
import {
|
|
Injectable,
|
|
NestInterceptor,
|
|
ExecutionContext,
|
|
CallHandler,
|
|
} from '@nestjs/common';
|
|
import { Observable, map } from 'rxjs';
|
|
import { ApiResponse } from '../response-format';
|
|
|
|
/**
|
|
* 规范返回格式
|
|
*/
|
|
@Injectable()
|
|
export class ResponseInterceptor<T>
|
|
implements NestInterceptor<T, ApiResponse<T>>
|
|
{
|
|
intercept(
|
|
context: ExecutionContext,
|
|
next: CallHandler,
|
|
): Observable<ApiResponse<T>> {
|
|
return next.handle().pipe(
|
|
map((data) => ({
|
|
success: true,
|
|
data,
|
|
message: '操作成功',
|
|
})),
|
|
);
|
|
}
|
|
}
|