This commit is contained in:
parent
b3b7e9c213
commit
b64b91e50f
|
@ -28,21 +28,33 @@ module.exports = function(Self) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* Intercept GET request for find
|
|
||||||
*/
|
|
||||||
this.beforeRemote('find', async ctx => {
|
this.beforeRemote('find', async ctx => {
|
||||||
isSelect = true;
|
const defaultLimit = this.app.orm.selectLimit;
|
||||||
const filter = ctx.args.filter || {};
|
const filter = ctx.args.filter || {limit: defaultLimit};
|
||||||
if (filter.limit === undefined) {
|
|
||||||
filter.limit = this.app.orm.selectLimit;
|
if (filter.limit > defaultLimit) {
|
||||||
|
filter.limit = defaultLimit;
|
||||||
ctx.args.filter = filter;
|
ctx.args.filter = filter;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.observe('loaded', async({data}) => {
|
this.afterRemote('find', async({result}) => {
|
||||||
if (!isSelect) return;
|
const length = Array.isArray(result) ? result.length : result ? 1 : 0;
|
||||||
const length = Array.isArray(data) ? data.length : data ? 1 : 0;
|
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
||||||
|
});
|
||||||
|
|
||||||
|
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 length = Array.isArray(result) ? result.length : result ? 1 : 0;
|
||||||
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue