Is there any way to sort populated data in v4?

System Information
  • Strapi Version: 4.0.0
  • Operating System: windows 11
  • Database: postgresql
  • Node Version: 14.18.1
  • NPM Version:
  • Yarn Version: 1.22.15

I can get articles based on category by following link: http://localhost:1337/api/categories/1?fields=title&populate=articles&sort=createdAt:desc but isn’t sorted, I tried to create custom route

module.exports = {
routes: [
{
method: “GET”,
path: “/articles/:category/:id”,
handler: “articlesbycat.getArticlesByCat”,
},
],
};

module.exports = {
getArticlesByCat: async (ctx, next) => {
try {
ctx.body = “ok”;
} catch (err) {
ctx.body = err;
}
},
};

how do i create a custom controller that can get recent articles by category ?

2 Likes