在Loopback中施加最大限制

时间:2015-06-08 18:53:31

标签: swagger loopbackjs strongloop

有没有办法在Loopback中设置最大限制。我想象这样的事情:

MyModel.paginateFind = function(filter, page, cb){

    // Set max limit of 1000
    if (filter.limit > 1000) filter.limit = 1000;

    // Set pagination
    filter.skip = filter.limit * (page - 1);

    // Call the standard find function with the new filter
    MyModel.find(filter, function(err, res){
        cb(err, res);
    });
}

MyModel.remoteMethod(
    'paginatedFind',
    {
        http: {path: '/', verb: 'get'},
        accepts: [
            {arg: 'filter', type: 'object'},
            {arg: 'page',   type: 'number'}
        ],
        returns: {arg: 'result', type: 'object'}
    }
);

当过滤器格式化为json时,这种方式有效,但不是这种格式:http://localhost:3000/api/MyModel?filter=[where][country]=DE。如何使用标准的StongLoop过滤器格式?

1 个答案:

答案 0 :(得分:0)

根据文档here的格式应如下所示:

api/MyModel?filter[where][country]=DE