我的前端查询:
http://localhost:8888/api/employees?access_token=adsafsaf&filter= {%二条%22:{%22emp_code%22:%22EMPT01%22}}
原始查询:{"其中":{" emp_code":" EMPT01"}}
我正在尝试动态地在上面的传入请求中添加"代码" 字段。
Employee.observe('access', function (ctx, next) {
// first way, it is not adding "orgId" field.
ctx.query.where = {
orgId: ctx.options.data.orgId
};
// second way, it is not adding "orgId" field.
const query = {};
query['orgId'] = ctx.options.data.orgId;
ctx.query.where = query;
next();
});
请有人指导我,哪里出错了?
Loopback版本:3
由于
答案 0 :(得分:1)
我通过这种方式解决了这个问题。
Employee.observe('access', function (ctx, next) {
// instead single , check both condition
if(ctx.query.where !=undefined){
// if the request does not contain **where** then add it & filter it
ctx.query.where.orgId = ctx.options.data.orgId;
}else{
ctx.query.where = {
orgId: ctx.options.data.orgId
};
}
next();
});