fix: negative limit without maxLimit (graphql)

This commit is contained in:
vincentbpro 2021-11-08 17:17:56 +01:00
parent 3e5cea0cbc
commit 73e5b672fd
2 changed files with 4 additions and 4 deletions

View File

@ -26,7 +26,7 @@ const withMaxLimit = (limit, maxLimit = -1) => {
// Ensure minimum page & pageSize values (page >= 1, pageSize >= 0, start >= 0, limit >= 0)
const ensureMinValues = ({ start, limit }) => ({
start: Math.max(start, 0),
limit: Math.max(limit, 1),
limit: limit === -1 ? limit : Math.max(limit, 1),
});
const ensureMaxValues = (maxLimit = -1) => ({ start, limit }) => ({

View File

@ -25,9 +25,9 @@ module.exports = ({ strapi }) => {
const { start, limit } = args;
const total = await strapi.entityService.count(resourceUID, args);
const pageSize = limit;
const pageCount = limit === 0 ? 0 : Math.ceil(total / limit);
const page = limit === 0 ? 1 : Math.floor(start / limit) + 1;
const pageSize = limit === -1 ? total : limit;
const pageCount = limit === -1 ? 1 : Math.ceil(total / limit);
const page = limit === -1 ? 1 : Math.floor(start / limit) + 1;
return { total, page, pageSize, pageCount };
},