-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa72b55
commit 8395e69
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/common/interceptors/wrap-response/wrap-response.interceptor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { WrapResponseInterceptor } from './wrap-response.interceptor'; | ||
|
||
describe('WrapResponseInterceptor', () => { | ||
it('should be defined', () => { | ||
expect(new WrapResponseInterceptor()).toBeDefined(); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
src/common/interceptors/wrap-response/wrap-response.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// nest g interceptor common/interceptors/wrap-response | ||
|
||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common'; | ||
// import { Observable, tap } from 'rxjs'; | ||
import { Observable, map } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class WrapResponseInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
console.log('Before...'); | ||
// return next.handle().pipe(tap((data) => console.log('After...', data))); | ||
// 将返回的数据放到 {data: xxx} 中 | ||
return next.handle().pipe(map((data) => ({ data }))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters