#7524 add limit on GET with filter param #2802
|
@ -31,20 +31,19 @@ module.exports = function(Self) {
|
|||
/*
|
||||
* Intercept GET request for find
|
||||
*/
|
||||
this.beforeRemote('find', async function(ctx) {
|
||||
this.beforeRemote('find', async ctx => {
|
||||
isSelect = true;
|
||||
const filter = ctx.args.filter || {};
|
||||
// console.log(this.dataSource, Self.dataSource); undefined/null
|
||||
if (filter.limit === undefined) {
|
||||
filter.limit = 1/* limit */;
|
||||
filter.limit = this.app.orm.selectLimit;
|
||||
ctx.args.filter = filter;
|
||||
}
|
||||
});
|
||||
|
||||
this.observe('loaded', async function({data}) {
|
||||
this.observe('loaded', async({data}) => {
|
||||
if (!isSelect) return;
|
||||
const length = Array.isArray(data) ? data.length : data ? 1 : 0;
|
||||
if (length >= 1) throw new UserError('Too many records');
|
||||
if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
|
||||
});
|
||||
|
||||
// Register field ACL validation
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = async function(app) {
|
||||
if (!app.orm) {
|
||||
const ormConfig = await app.models.OrmConfig.findOne();
|
||||
app.orm = ormConfig;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue