This commit is contained in:
parent
3adb73cddf
commit
bbe5306088
|
@ -5,7 +5,6 @@ const utils = require('loopback/lib/utils');
|
|||
|
||||
module.exports = function(Self) {
|
||||
Self.ParameterizedSQL = ParameterizedSQL;
|
||||
let isSelect;
|
||||
|
||||
require('../methods/vn-model/getSetValues')(Self);
|
||||
require('../methods/vn-model/getEnumValues')(Self);
|
||||
|
@ -28,7 +27,9 @@ module.exports = function(Self) {
|
|||
};
|
||||
});
|
||||
|
||||
this.beforeRemote('find', async ctx => {
|
||||
this.beforeRemote('**', async ctx => {
|
||||
if (!this.hasFilter(ctx)) return;
|
||||
|
||||
const defaultLimit = this.app.orm.selectLimit;
|
||||
const filter = ctx.args.filter || {limit: defaultLimit};
|
||||
|
||||
|
@ -38,22 +39,10 @@ module.exports = function(Self) {
|
|||
}
|
||||
});
|
||||
|
||||
this.afterRemote('find', async({result}) => {
|
||||
const length = Array.isArray(result) ? result.length : result ? 1 : 0;
|
||||
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
||||
});
|
||||
this.afterRemote('**', async ctx => {
|
||||
if (!this.hasFilter(ctx)) return;
|
||||
|
||||
this.beforeRemote('filter', async ctx => {
|
||||
const defaultLimit = this.app.orm.selectLimit;
|
||||
const filter = ctx.args.filter || {limit: defaultLimit};
|
||||
|
||||
if (filter.limit > defaultLimit) {
|
||||
filter.limit = defaultLimit;
|
||||
ctx.args.filter = filter;
|
||||
}
|
||||
});
|
||||
|
||||
this.afterRemote('filter', async({result}) => {
|
||||
const {result} = ctx;
|
||||
const length = Array.isArray(result) ? result.length : result ? 1 : 0;
|
||||
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
||||
});
|
||||
|
@ -357,6 +346,12 @@ module.exports = function(Self) {
|
|||
|
||||
checkInsertAcls(ctx) {
|
||||
return this.checkAcls(ctx, 'insert');
|
||||
},
|
||||
|
||||
hasFilter(ctx) {
|
||||
return ctx.req.method.toUpperCase() === 'GET' &&
|
||||
ctx.method.accepts.some(x => x.arg === 'filter' && x.type.toLowerCase() === 'object');
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue