prisma-pagination icon indicating copy to clipboard operation
prisma-pagination copied to clipboard

TypeError: t.count is not a function

Open GarryOne opened this issue 2 years ago • 1 comments

Error

TypeError: t.count is not a function
    at /Users/mac/www/cysiam/CYSIAM-api/node_modules/prisma-pagination/dist/index.js:1:492
    at ClientService.findAll (/Users/mac/www/cysiam/CYSIAM-api/dist/src/modules/client/client.service.js:31:16)
    at ClientController.getAllClients (/Users/mac/www/cysiam/CYSIAM-api/dist/src/modules/client/client.controller.js:25:35)
    at /Users/mac/www/cysiam/CYSIAM-api/node_modules/@nestjs/core/router/router-execution-context.js:38:29
    at async /Users/mac/www/cysiam/CYSIAM-api/node_modules/@nestjs/core/router/router-execution-context.js:46:28
    at async /Users/mac/www/cysiam/CYSIAM-api/node_modules/@nestjs/core/router/router-proxy.js:9:17

My usage example:

const paginate = createPaginator({ perPage: 5 });

    return paginate<any, any>(
      this.prisma.clients.findMany({
        skip,
        take,
        where,
        orderBy,
      }),
    );

Versions: Node: 16.10.0 Prisma: 4.4.0 prisma-pagionation: 0.2.3

GarryOne avatar Oct 05 '22 17:10 GarryOne

You provided the entire prisma findMany method to The paginate function arguments. which is incorrect.

The paginate function takes three arguments.

first: only the model. (this.prisma.clients) second: findMany options. (only one object containing all the options except skip & take) ({ where, orderBy }) third: The pagination option which are ({ perPage: 10, page: 1})

const paginate = createPaginator();

return paginate<any, any>(
  this.prisma.clients,
  { where, orderBy },
  { page: 1, perPage: 5 }
);

smohammadhn avatar Mar 07 '24 15:03 smohammadhn