feat: refs #7524 no apply limit #2921
|
@ -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;
|
||||||
juan marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
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;
|
||||||
jorgep marked this conversation as resolved
Outdated
juan
commented
Comprobar Comprobar `ctx.method.noLimit` en la función `hasFilter` para no repetir lógica
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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')
|
||||||
|
|
Loading…
Reference in New Issue
Comprobar
ctx.method.noLimit
en la funciónhasFilter
para no repetir lógica