Closed essamsalah closed 4 years ago
Here is another suggestion that would make it easyier to copy/paste in every controller:
module.exports = {
find: async ctx => {
const modelName = "<ModelName>";
const srv = strapi.services[modelName];
ctx.set("Content-Range", await srv.count(ctx.query));
if (ctx.query._q) {
return srv.search(ctx.query);
} else {
return srv.find(ctx.query);
}
}
};
Thank you @essamsalah. Updated the readme file 👍
I noticed that using the code as it-is from the Example will throw an error in Strapi console
I fixed the error by sending the ctx.query as a parameter in the count method plus using the fully qualified class name as below:
ctx.set('Content-Range', await strapi.services.<Model>.count(ctx.query));
My Node/Strapi : Version: 3.0.0-alpha.25.2 (node v11.1.0)