How to implement pagination in NestJS with TypeORM?

Answer

You can find some nice example in this project. In short typeorm has a really nice method specific to this usecase findAndCount.

async findAll(query): Promise<Paginate> {
const take = query.take || 10
const skip = query.skip || 0
const keyword = query.keyword || ''

const [result, total] = await this.userRepository.findAndCount(
{
where: { name: Like('%' + keyword + '%') }, order: { name: "DESC" },
take: take,
skip: skip
}
);

return {
data: result,
count: total
}
}

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---