strapi-plugin-comments: [CU-23e47df] Pagination not working on V4

I can’t use pagination in query {{host}}/api/comments/api::post.post:1/flat?pagination[pageSize]=1 Always got error Undefined attribute level operator pageSize

I looked at the source code and I found the function findAllFlat in server/controllers/client.js and found that sort and pagination definitely does not exist in ctx.

So i changed const { params = {}, query, sort, pagination } = ctx; to const { params = {}, query } = ctx;

And add const { sort, pagination } = query; before call service findAllFlat

Also i go to server/services/common.js add code in function findAllFlat like this

delete query.pagination;
if (pagination && isObject(pagination)) {
    const { page = 1, pageSize = 10 } = pagination;
    queryExtension = {
        ...queryExtension,
        offset: (page - 1) * pageSize,
        limit: pageSize,
    };
}

Plugin version: 2.0.4 & 2.0.3

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Its indeed tricky case and I’m analyzing couple possibilities here. Happy to work with you folks to get it done as community expect 😃

Let me check that @Tragio

@cyp3rius seems that the pagination[withCount] is not workig. The idea is to load x comments and then if there are more, show a “load more” button, however, pagination[withCount]=true does not have any effect on the response and I can’t see how much comments are there 🤔