refactor: refs #7524 wrap it up in a fn
gitea/salix/pipeline/pr-master This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-09-10 16:37:46 +02:00
parent 1ff1a97f29
commit e3b51c81f9
1 changed files with 6 additions and 4 deletions

View File

@ -28,7 +28,7 @@ module.exports = function(Self) {
}); });
this.beforeRemote('**', async ctx => { this.beforeRemote('**', async ctx => {
if (ctx.method.noLimit || !this.hasFilter(ctx)) return; if (!this.hasFilter(ctx)) return;
const defaultLimit = this.app.orm.selectLimit; const defaultLimit = this.app.orm.selectLimit;
const filter = ctx.args.filter || {limit: defaultLimit}; const filter = ctx.args.filter || {limit: defaultLimit};
@ -40,7 +40,7 @@ module.exports = function(Self) {
}); });
this.afterRemote('**', async ctx => { this.afterRemote('**', async ctx => {
if (ctx.method.noLimit || !this.hasFilter(ctx)) return; if (!this.hasFilter(ctx)) return;
const {result} = ctx; const {result} = ctx;
const length = Array.isArray(result) ? result.length : result ? 1 : 0; const length = Array.isArray(result) ? result.length : result ? 1 : 0;
@ -349,8 +349,10 @@ module.exports = function(Self) {
}, },
hasFilter(ctx) { hasFilter(ctx) {
return ctx.req.method.toUpperCase() === 'GET' && const {method, req} = ctx;
ctx.method.accepts.some(x => x.arg === 'filter' && x.type.toLowerCase() === 'object'); if (method.noLimit) return false;
return req.method.toUpperCase() === 'GET' &&
method.accepts.some(x => x.arg === 'filter' && x.type.toLowerCase() === 'object');
}, },
}); });
}; };