Skip to content

Commit

Permalink
feature(user should be able to receive notification):user should be a…
Browse files Browse the repository at this point in the history
…ble to receive notification

user should be able to receive notification
[finishes #166841022]
  • Loading branch information
Cavdy committed Jul 24, 2019
1 parent c819fcf commit f6717f4
Show file tree
Hide file tree
Showing 20 changed files with 600 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ lib
lcov.info

# Ignore index.html
src/test.html
src/test.html
179 changes: 172 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"chai-http": "^4.3.0",
"cloudinary": "^1.14.0",
"cors": "^2.8.4",
"debug": "^4.1.1",
"dotenv": "^6.2.0",
"ejs": "^2.6.1",
"errorhandler": "^1.5.0",
Expand Down Expand Up @@ -68,7 +69,9 @@
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.4",
"pg": "^7.11.0",
"pg-connection-string": "^2.1.0",
"pg-hstore": "^2.3.3",
"pusher": "^2.2.1",
"randomstring": "^1.1.5",
"request": "^2.87.0",
"sequelize": "^5.8.12",
Expand All @@ -84,13 +87,13 @@
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.16.0",
"faker": "^4.1.0",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0",
"eslint-plugin-prettier": "^3.1.0",
"faker": "^4.1.0",
"morgan": "^1.9.1",
"nodemon": "^1.19.1",
"nyc": "^14.1.1",
"prettier": "^1.18.2"
"prettier": "^1.18.2",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0"
}
}
19 changes: 14 additions & 5 deletions src/controllers/CommentController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Comment, CommentHistory, CommentLike } from '../db/models';
import notification from '../helpers/notification';
import findItem from '../helpers/findItem';

/**
* @description This controller handles comment request
* @class CommentController
Expand All @@ -15,18 +18,24 @@ class CommentController {
static async addCommentTocomment(req, res) {
try {
const articleId = res.locals.articleObject.id;

const { userName, bio, imageUrl } = res.locals.articleObject.User;
const { commentBody } = req.body;
const userId = req.user;

const commentObject = {
userId,
articleId,
commentBody,
commentBody
};

const comment = await Comment.create(commentObject);

// SEND ARTICLE AUTHOR NOTIFICATION ON COMMENT
const loggedInUser = await findItem.getUser(userId);
const authorId = res.locals.articleObject.User.id;
const articleTitle = res.locals.articleObject.title;
notification(authorId, `${loggedInUser.firstName} ${loggedInUser.lastName} commented on ${articleTitle}`);

const { id, createdAt, updatedAt } = comment;
return res.status(201).json({
Expand All @@ -52,8 +61,8 @@ class CommentController {
message: error.message,
});
}
};

}
/**
* @static
* @description The get all comment method
Expand Down
Loading

0 comments on commit f6717f4

Please sign in to comment.