in api/article/content-type/article/article.js i wrote the code bellow: ‘use strict’;
module.exports = {
lifecycles: {
async afterFindOne(params) {
const article = await strapi.query('article').findOne({id: params.id});
if (article) {
await strapi.query('article').update(
{id: params.id},
{views: parseInt(article.views) + 1}
);
}
}
}
};
i have a field in the article collection named views it has a default value 0 and i want it to increment automatically whenever a user visits that article how can this be done?