Impose max limit in Loopback

672 views Asked by At

Is there a way to set a max limit in Loopback. I imagine something like this:

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'}
    }
);

This works when the filter is formated as json, but not in this format: http://localhost:3000/api/MyModel?filter=[where][country]=DE. How can I use the standard StongLoop filter format?

1

There are 1 answers

0
JSimonsen On

The format, according the to documentation here should look like this:

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