如何在Nest.js中实现嵌套拦截器?
我有两个拦截器:UsersInterceptor
和PostsInterceptor
UsersInterceptor:
@Injectable()
export class UsersInterceptor<T> implements NestInterceptor<T, Response<T>> {
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>> {
return next.handle().pipe(map(data => ({
id: data._id,
email: data.email,
createdAt: data.createdAt
})));
}
}
PostsInterceptor:
@Injectable()
export class PostsInterceptor<T> implements NestInterceptor<T, Response<T>> {
intercept(context: ExecutionContext, next: CallHandler): Observable<Response<T>> {
return next.handle().pipe(map(data => ({
id: data._id,
title: data.title,
content: data.content,
user: {}, // I want the UsersInterceptor result here. I have the user's data in data.user
createdAt: data.createdAt
})));
}
}
现在,我想在使用UserInterceptor
时将user
的结果放入PostsInterceptor
中的Binding<Bool>
对象中。
答案 0 :(得分:0)
As described in the request lifecycle docs,拦截器按照绑定的顺序处理传入的请求,并按照绑定的相反顺序处理传出的响应。这意味着,如果您像Item {
id:main_container
width: parent.width
height: parent.height
//////////////////////js///////////////////////////////////////
function test(){
var foo = new Array(2);
for(var i = 0; i < foo.length; i++){
console.log("i am here");
var newObject = Qt.createQmlObject('import QtQuick 2.0; Rectangle { color: "red"; border.color: "black"; border.width: 5; width: 150; height: 150}',body);//i noticed Layout.preferedWidth & height here occurs error so i have to use width and height
}
}
////////////////////////////////
Rectangle{
id: home_main_container
anchors.fill: parent
Rectangle{
id:header
width: parent.width
height: parent.height/10
anchors.top: parent.top
color: b1
}
Rectangle{
id:body
width: parent.width
height: parent.height*(8/10)
anchors.top: header.bottom
anchors.horizontalCenter: parent.horizontalCenter
ColumnLayout{
id:body_part1
width: parent.width
height: parent.height/4
anchors.top: parent.bottom
Component.onCompleted: test();
}
}
Rectangle{
id:footer
width: parent.width
height: parent.height/10
anchors.bottom: parent.bottom
color: b1
}
}
}
这样绑定拦截器,那么您应该能够在@UseInterceptors(PostInterceptor, UserInterceptor)
UserInterceptor
的返回