diff --git a/.codeclimate.yml b/.codeclimate.yml index 5e27232..d887cb4 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,6 +1,8 @@ exclude_patterns: -- "src/db/" -- "tests/" + - "src/db/" + - "tests/" checks: similar-code: enabled: false + method-lines: + enabled: false diff --git a/src/controllers/articleController.js b/src/controllers/articleController.js index bb0fe1c..d520ca1 100644 --- a/src/controllers/articleController.js +++ b/src/controllers/articleController.js @@ -155,6 +155,7 @@ class ArticleManager { const articlesList = await Articles.findAll({ offset: pageNumber.offset, limit: pageNumber.limit, + order: [['createdAt', 'DESC']], include: [{ as: 'author', model: Users, diff --git a/src/controllers/shareArticleController.js b/src/controllers/shareArticleController.js index e5ef57c..2ac29b1 100644 --- a/src/controllers/shareArticleController.js +++ b/src/controllers/shareArticleController.js @@ -1,4 +1,3 @@ -import open from 'open'; /** * share article controller */ @@ -15,7 +14,6 @@ class ShareArticleManager { message: 'Article to share on E-mail', link: `mailto:?subject=${slug}&body=${link}` }); - await open(`mailto:?subject=${slug}&body=${link}`); } /** @@ -31,7 +29,6 @@ class ShareArticleManager { // share article on twitter link: `https://twitter.com/intent/tweet?text=${link}` }); - await open(`https://twitter.com/intent/tweet?text=${link}`); } /** @@ -46,7 +43,6 @@ class ShareArticleManager { message: 'Post to share on Facebook', link: `https:www.facebook.com/sharer/sharer.php?u=${shareLink}` }); - await open(`https:www.facebook.com/sharer/sharer.php?u=${shareLink}`); } /** @@ -60,7 +56,6 @@ class ShareArticleManager { message: 'Article to share on Whatsapp', link: `https://wa.me/?text=${req.article.link}` }); - await open(`https://wa.me/?text=${req.article.link}`); } } export default ShareArticleManager; diff --git a/src/controllers/statisticController.js b/src/controllers/statisticController.js index dd0c81f..0906257 100644 --- a/src/controllers/statisticController.js +++ b/src/controllers/statisticController.js @@ -14,7 +14,7 @@ class StatisticManager { const { id } = req.user; const { slug } = req.params; const findArticle = await Articles.findOne({ where: { slug } }); - if (!findArticle) return res.status(200).json({ error: 'No article found' }); + if (!findArticle) return res.status(404).json({ error: 'No article found' }); const [result, created] = await Statistics.findOrCreate({ where: { userId: id, articleId: findArticle.id }, defaults: { numberOfReading: 1 } }); @@ -41,13 +41,14 @@ class StatisticManager { const countTotalArticlesRead = await Statistics.count({ where: { userId: id } }); const articlesRead = await Statistics.findAll({ where: { userId: id }, + order: [['updatedAt', 'DESC']], attributes: [ ['numberOfReading', 'TimesArticleRead'], ['updatedAt', 'lastSeen']], include: [ { model: Articles, - attributes: ['title', 'slug', 'body'], + attributes: ['title', 'slug', 'description', 'body'], } ] });