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 => { this.beforeRemote('**', async ctx => {
if (!this.hasFilter(ctx)) return; if (this.hasNoLimit(ctx) || !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};
if (filter.limit > defaultLimit) { if (!filter.limit || filter.limit > defaultLimit) {
filter.limit = defaultLimit; filter.limit = defaultLimit;
ctx.args.filter = filter; ctx.args.filter = filter;
} }
}); });
this.afterRemote('**', async ctx => { this.afterRemote('**', async ctx => {
if (!this.hasFilter(ctx)) return; if (this.hasNoLimit(ctx) || !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;
@ -351,6 +351,10 @@ module.exports = function(Self) {
hasFilter(ctx) { hasFilter(ctx) {
return ctx.req.method.toUpperCase() === 'GET' && return ctx.req.method.toUpperCase() === 'GET' &&
ctx.method.accepts.some(x => x.arg === 'filter' && x.type.toLowerCase() === 'object'); 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, required: true,
description: 'Filter defining where and paginated data', description: 'Filter defining where and paginated data',
http: {source: 'query'} http: {source: 'query'}
}, {
arg: 'noLimit',
type: 'Boolean',
required: false,
}], }],
returns: { returns: {
type: ['Object'], 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}; const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object') if (typeof options == 'object')