feat: refs #7524 no apply limit
gitea/salix/pipeline/pr-master There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-09-04 14:52:53 +02:00
parent 5f714df73b
commit e3015a6559
2 changed files with 12 additions and 4 deletions

View File

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

View File

@ -8,6 +8,10 @@ module.exports = Self => {
required: true,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}, {
arg: 'noLimit',
type: 'Boolean',
required: false,
}],
returns: {
type: ['Object'],
@ -19,7 +23,7 @@ module.exports = Self => {
}
});
Self.getBalance = async(ctx, filter, options) => {
Self.getBalance = async(ctx, filter, noLimit, options) => {
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')