Skip to content

Commit

Permalink
Merge pull request #61 from andela/bg-fix-bugs-in-reading-stats
Browse files Browse the repository at this point in the history
Fix all bugs in reading stats
  • Loading branch information
j4l13n committed Sep 19, 2019
2 parents 16d9035 + 7369383 commit a8fd7de
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
exclude_patterns:
- "src/db/"
- "tests/"
- "src/db/"
- "tests/"
checks:
similar-code:
enabled: false
method-lines:
enabled: false
1 change: 1 addition & 0 deletions src/controllers/articleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/controllers/shareArticleController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import open from 'open';
/**
* share article controller
*/
Expand All @@ -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}`);
}

/**
Expand All @@ -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}`);
}

/**
Expand All @@ -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}`);
}

/**
Expand All @@ -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;
5 changes: 3 additions & 2 deletions src/controllers/statisticController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
});
Expand All @@ -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'],
}
]
});
Expand Down

0 comments on commit a8fd7de

Please sign in to comment.