Skip to content

Commit

Permalink
168048575-bug(voteArticle): change vote article response
Browse files Browse the repository at this point in the history
[Fixes #168048575]
  • Loading branch information
caleb-42 committed Aug 22, 2019
1 parent 3c1515a commit 136fd9f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ logs
.DS_Store
package-lock.json
npm-debug.log*
.vscode/launch.json

# Runtime data
pids
Expand Down
37 changes: 31 additions & 6 deletions controllers/articles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export default {
status = JSON.parse(status);
const article = await db.Article.findOne({
where: {
slug
slug,
}
});

Expand Down Expand Up @@ -492,14 +492,39 @@ export default {
type: 'like'
});
}

const upvotes = await db.ArticleVote.getArticleVotes({ ...voteDetails, status: true });
const downvotes = await db.ArticleVote.getArticleVotes({ ...voteDetails, status: false });
const upVote = await db.ArticleVote.findAll({
where: {
articleId: voteDetails.articleId,
status: true,
},
attributes: ['status'],
include: [
{
model: db.User,
as: 'user',
attributes: ['username']
}
]
});
const downVote = await db.ArticleVote.findAll({
where: {
articleId: voteDetails.articleId,
status: false,
},
attributes: ['status'],
include: [
{
model: db.User,
as: 'user',
attributes: ['username']
}
]
});

return res.status(resStatus).json({
message,
upvotes,
downvotes
upVote,
downVote
});
} catch (e) {
/* istanbul ignore next */
Expand Down

0 comments on commit 136fd9f

Please sign in to comment.