View counter in strapi: With lifecycle hooks? But how to use them?

Seems that there was a problem with the afterfindOne-hook for unpublished articles. I got an 500 internal server error in this case.

With this hook it works:

module.exports = {
  lifecycles: {
    async afterFindOne(result, params, populate) {
      if(result) {
        const article = await strapi.query('article').find({id: result.id});

        if (article) {
          await strapi.query('article').update(
            {id: article[0].id},
            {views: parseInt(article[0].views) + 1}
          );
        }
      }
    }
  }
};