ppetzold / nestjs-paginate

Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework :book::paperclip:
MIT License
438 stars 99 forks source link

suggestion: to add multiple sortBy query param #871

Closed peterLam2 closed 8 months ago

peterLam2 commented 8 months ago

typeorm support the following structure with queryBuilder

CM.getRepository(User)
      .createQueryBuilder('user')
      .select(["name", "id"])
      .orderBy('user.createdDate', 'ASC')
      .addOrderBy('user.createdTime', 'ASC') 

and also

    const users = await User.find({
      where: { userId },
      order: { createdAt: "ASC", createdTime: "ASC" },
     });

In this library, while the sortBy is allow user to input multiple sortBy value, but it won't work at all. because of the following code in /nestjs-paginate/lib/decorator.js

const multipleSplit = (param, res) => {
    const items = param.split(':');
    if (items.length === 2) {
        res.push(items);
    }
};
const sortBy = parseParam(query.sortBy, multipleSplit);

is this any consideration for not supporting multiple sortBy, if not , it would be great to allow sort-by to have more value. for example to support the following structure and split it by comma.

http://localhost:3000/cats?limit=5&page=2&sortBy=color:DESC,title:ASC

ppetzold commented 8 months ago

We do support multiple sortBy columns like below:

http://localhost:3000/cats?limit=5&page=2&sortBy=color:DESC&sortBy=title:ASC