mirror of
https://github.com/strapi/strapi.git
synced 2025-08-25 00:59:25 +00:00
fix: avoid divided by zero issue
This commit is contained in:
parent
7a85b712f9
commit
a5ac20dda0
@ -23,11 +23,12 @@ module.exports = ({ strapi }) => {
|
|||||||
async resolve(parent) {
|
async resolve(parent) {
|
||||||
const { args, resourceUID } = parent;
|
const { args, resourceUID } = parent;
|
||||||
const { start, limit } = args;
|
const { start, limit } = args;
|
||||||
|
const safeLimit = Math.max(limit, 1);
|
||||||
|
|
||||||
const total = await strapi.entityService.count(resourceUID, args);
|
const total = await strapi.entityService.count(resourceUID, args);
|
||||||
const pageSize = limit === -1 ? total - start : limit;
|
const pageSize = limit === -1 ? total - start : safeLimit;
|
||||||
const pageCount = limit === -1 ? 1 : Math.ceil(total / limit);
|
const pageCount = limit === -1 ? safeLimit : Math.ceil(total / safeLimit);
|
||||||
const page = limit === -1 ? 1 : Math.floor(start / limit) + 1;
|
const page = limit === -1 ? safeLimit : Math.floor(start / safeLimit) + 1;
|
||||||
|
|
||||||
return { total, page, pageSize, pageCount };
|
return { total, page, pageSize, pageCount };
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user