Sorting Support
hichemfantar opened this issue · comments
Can you add sorting support? It's a very useful feature.
How do you mean? You're able to provide a queryBuilder so you can build you're own query to the paginate func
https://github.com/nestjsx/nestjs-typeorm-paginate#querybuilder
const queryBuilder = this.repository.createQueryBuilder('c');
queryBuilder.orderBy('c.name', 'DESC')
.where('c.somethings = :something', { something: 'this' });
return paginate<CatEntity>(queryBuilder, options);
I've implemented sorting and join feature in my CRUD base service class: https://gist.github.com/mnixry/700ea483b9c632c1a025056ddde82f69
I hope my implementation can provide you with a little reference
Think I understand, sorting as in order + reversing the order. This can be done already using the findManyOptions
paginate<Entity>(this.repo, options, {
order: {
[key]: 'ASC',
},
})
Where
key
is keyof Entity
It's a pretty open method that allows for any implementation. In @mnixry answer, it's pretty complex but does the job! And is an example of allowing any implementation! Looks pretty decent <3