feat: refs #7524 no apply limit #2921

Merged
jorgep merged 8 commits from 7524-hotfix-addNoLimit into master 2024-09-10 14:48:21 +00:00
2 changed files with 12 additions and 4 deletions
Showing only changes of commit e3015a6559 - Show all commits

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')