Skip to content

Commit

Permalink
Merge 925eaff into ad85cb6
Browse files Browse the repository at this point in the history
  • Loading branch information
McHardex committed May 30, 2019
2 parents ad85cb6 + 925eaff commit a232cc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions server/controllers/comment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const post = async (req, res) => {
createdAt: comment.createdAt,
updatedAt: comment.updatedAt,
likes_count: comment.likes_count,
user_id: comment.user_id,
commentOwner,
},
});
Expand Down Expand Up @@ -127,6 +128,7 @@ const updateComment = async (req, res) => {
await CommentHistory.create({
comment_id: res.locals.comment.id,
body: res.locals.comment.body,
createdAt: res.locals.comment.updatedAt,
});
}

Expand Down
13 changes: 10 additions & 3 deletions server/helpers/comment-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,24 @@ const getCommentAndHistories = async (Comment, CommentHistory, commentid) => {
where: {
id: commentid,
},
attributes: ['id', 'likes_count', 'user_id', 'body', 'createdAt'],
attributes: [
'id',
'likes_count',
'user_id',
'body',
'createdAt',
'updatedAt',
],
include: [
{
model: CommentHistory,
required: false,
as: 'histories',
order: ['body'],
attributes: ['id', 'comment_id', 'body', 'updatedAt'],
attributes: ['id', 'comment_id', 'body', 'updatedAt', 'createdAt'],
},
],
order: [['histories', 'updatedAt', 'desc']],
order: [['histories', 'updatedAt', 'asc']],
});
} catch (err) {
return err;
Expand Down
6 changes: 4 additions & 2 deletions tests/comment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ describe('GET COMMENTS AND EDIT HISTORIES', () => {
'body',
'createdAt',
'histories',
'likes_count'
'likes_count',
'updatedAt'
);
expect(res.body.comment[0].histories[0]).to.have.all.keys(
'id',
'body',
'comment_id',
'updatedAt'
'updatedAt',
'createdAt'
);
expect(res.body.comment[0].histories[0].body).equal('deep write up');
done();
Expand Down

0 comments on commit a232cc2

Please sign in to comment.