Sorting
How to sort data in VitNode.
In some cases, you may need to sort the data in the database. VitNode provides a sorting system to order the query result.
Pagination Required
Sorting system is based on Pagination System. If you don't want
to use the pagination system you can use the orderBy
argument directly in the findMany()
method.
Create enum
First, you need to create an enum type in shared
folder to define the sorting options.
Enum should be defined outside file of class with types. Read more here Enums in DTO.
Extend query DTO
Next, you need to extend the query DTO to include the sorting options. Create sortBy
and sortDirection
properties in the query DTO and mark them as optional.
Usage in service
Finally, you can use the sorting options in the service to sort the data.
Frontent integration
Frontend API
You can read how to implement Sorting API here.