Skip to content

Commit

Permalink
Merge 673fbf5 into bfb60f5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaman-dedy committed May 6, 2019
2 parents bfb60f5 + 673fbf5 commit d4444a7
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 148 deletions.
24 changes: 13 additions & 11 deletions controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import shareTemplate from '../helpers/sendEmail/emailTemplates';
import Mailer from '../helpers/sendEmail/mailer';

const { shareArticleTemplate } = shareTemplate;

const notification = new Notification();

const {
article: Article,
Expand Down Expand Up @@ -36,7 +36,7 @@ class ArticleController {
* @param {Object} res
* @returns {Object} this will return created articles
*/
static create(req, res) {
create(req, res) {
// @initial article
const newArticle = {
title: req.body.title,
Expand All @@ -54,8 +54,8 @@ class ArticleController {
}
});
const message = `${user.username} published a new article`;
await Notification.createFollower(article.author, message);
await Notification.sendFollower(article.author, message);
await notification.createNotificationForFavorite(article.author, message);
await notification.sendNotificationToFollower(article.author, message);
res.status(201).json({ status: 201, message: 'Article created successfully', article });
})
.catch(error => res.status(500).json({ error: `something wrong please try again. ${error}` }));
Expand All @@ -67,7 +67,7 @@ class ArticleController {
* @param {Object} res get all created article
* @returns {Object} return all created article
*/
static getArticle(req, res) {
getArticle(req, res) {
const {
page = 1
} = req.query;
Expand Down Expand Up @@ -98,7 +98,7 @@ class ArticleController {
* @param {*} res
* @returns {*} - will return an object
*/
static shareEmail(req, res) {
shareArticle(req, res) {
mailOptions.to = SHARE_WITH;
mailOptions.html = shareArticleTemplate(req.params.articleId);
const mailer = new Mailer();
Expand All @@ -112,7 +112,7 @@ class ArticleController {
* @param {Object} res updated article
* @returns {Object} return updated article
*/
static updateArticle(req, res) {
updateArticle(req, res) {
// @updating articles
Article.update({
title: req.body.title,
Expand All @@ -127,8 +127,10 @@ class ArticleController {
})
.then(async (article) => {
const message = `Article with title "${article[1][0].title}" has been updated`;
await Notification.createFavorite(article[1][0].article_id, message, article[1][0].author);
await Notification.sendFavorite(article[1][0].article_id, message, article[1][0].author);
await notification.createNotificationForFavorite(article[1][0].article_id,
message, article[1][0].author);
await notification.sendNotificationToFavorites(article[1][0].article_id,
message, article[1][0].author);
res.status(200).json({
status: 200,
message: 'article updated successfully.',
Expand All @@ -145,7 +147,7 @@ class ArticleController {
* @param {Object} res delete article
* @returns {Object} return message and status
*/
static async deleteArticle(req, res) {
async deleteArticle(req, res) {
Article.destroy({
where: {
article_id: req.params.articleId
Expand All @@ -166,7 +168,7 @@ class ArticleController {
* @param {Object} res - view single article
* @returns {Object} return article
*/
static async singleArticle(req, res) {
async getSingleArticle(req, res) {
const user = req.user.id;
const { hasBookmarked } = req;
const {
Expand Down
4 changes: 2 additions & 2 deletions controllers/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Bookmark {
* @param {object} res - The response object
* @returns {object} It returns the request's response object
*/
static async createBookmark(req, res) {
async createBookmark(req, res) {
const userId = req.user.id;
const { articleId } = req.params;
try {
Expand All @@ -34,7 +34,7 @@ class Bookmark {
* @param {object} res - The response object
* @returns {object} It returns the request's response object
*/
static async allBookmark(req, res) {
async allBookmark(req, res) {
const userId = req.user.id;
try {
const allBookmarks = await bookmark.findAll({ where: { userId } });
Expand Down
25 changes: 14 additions & 11 deletions controllers/comment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import models from '../models/index';
import Notification from './notification';


const notification = new Notification();
const Comment = models.comments;
const User = models.user;
const Votes = models.votecomment;
Expand All @@ -16,7 +16,7 @@ class CommentController {
* @param {Object} res
* @returns {Object} will create a comment
*/
static create(req, res) {
create(req, res) {
// @comment
const newComment = {
body: req.body.content,
Expand All @@ -35,8 +35,10 @@ class CommentController {
User.findOne({ where: { id: comment.author } })
.then(async (user) => {
const message = `${user.username} commented on an article you favorite`;
await Notification.createFavorite(comment.articleId, message, comment.author);
await Notification.sendFavorite(comment.articleId, message, comment.author);
await notification.createNotificationForFavorite(comment.articleId,
message, comment.author);
await notification.sendNotificationToFavorites(comment.articleId,
message, comment.author);
res.status(201).json({ status: 201, comment });
});
});
Expand All @@ -48,7 +50,7 @@ class CommentController {
* @param {Object} res
* @returns {Object} - will return all comment related to an article
*/
static getAllComment(req, res) {
getAllComment(req, res) {
Comment.findAll({ where: { articleId: req.params.articleId } })
.then((comment) => {
if (comment.length === 0) {
Expand All @@ -64,7 +66,7 @@ class CommentController {
* @param {object} res
* @returns {object} return a json object
*/
static getEditedComment(req, res) {
getEditedComment(req, res) {
EditedCommentHistory.findAll({
where: { commentId: req.params.commentId }
})
Expand All @@ -82,16 +84,17 @@ class CommentController {
* @param {Object} res
* @returns {Object} -will return an updated Comment
*/
static updateComment(req, res) {
updateComment(req, res) {
Comment.update({ body: req.body.content },
{ where: { id: req.params.commentId }, returning: true })
.then((comment) => {
User.findOne({ where: { id: comment[1][0].author } })
.then(async (user) => {
const message = `${user.username} updated his comment on an article you favorite`;
await Notification.createFavorite(comment[1][0].articleId,
await notification.createNotificationForFavorite(comment[1][0].articleId,
message, comment[1][0].author);
await notification.sendNotificationToFavorites(comment[1][0].articleId,
message, comment[1][0].author);
await Notification.sendFavorite(comment[1][0].articleId, message, comment[1][0].author);
const edited = {
commentId: req.params.commentId,
userId: req.user.id,
Expand All @@ -113,7 +116,7 @@ class CommentController {
* @param {Object} res
* @returns {Object} -will delte a given comment
*/
static deleteComment(req, res) {
deleteComment(req, res) {
Comment.destroy({
where: { id: req.params.commentId },
returning: true
Expand All @@ -129,7 +132,7 @@ class CommentController {
* @param {Object} res view single comment
* @returns {Object} return a comment
*/
static async singleComment(req, res) {
async getSingleComment(req, res) {
const { user } = req;
const { commentId } = req.params;
const comment = await Comment.findByPk(commentId);
Expand Down
4 changes: 2 additions & 2 deletions controllers/commentLikes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommentVotesController {
* @param {response} res response
* @returns {message} message
*/
static async commentLikes(req, res) {
async likeComment(req, res) {
try {
const likeData = {
userId: req.user.id,
Expand Down Expand Up @@ -44,7 +44,7 @@ class CommentVotesController {
*/

// eslint-disable-next-line require-jsdoc
static async commentDislikes(req, res) {
async dislikeComment(req, res) {
try {
const dislikeData = {
userId: req.user.id,
Expand Down
8 changes: 4 additions & 4 deletions controllers/email/verifyLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const User = models.user;
* @exports
* @class
*/
class VerifyLink {
class LinkVerification {
/**
* Send the verification email to a user
* @param {Object} req - Requests from user
* @param {Object} res - Response to the user
* @returns {Object} Response
*/
static async sendEmail(req, res) {
async sendEmail(req, res) {
const { token, template } = req.body;
const decoded = jwt.decode(token, secretOrkey);
try {
Expand All @@ -45,7 +45,7 @@ class VerifyLink {
* @param {Object} res - Response to the user
* @returns {Object} Response
*/
static async activate(req, res) {
async activateAccount(req, res) {
try {
const { token } = req.params;
const decoded = jwt.decode(token, secretOrkey);
Expand Down Expand Up @@ -74,4 +74,4 @@ class VerifyLink {
}
}

export default VerifyLink;
export default LinkVerification;
8 changes: 4 additions & 4 deletions controllers/followers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FollowerController {
* @param {Object} res
* @return {Object} message
*/
static follow(req, res) {
followUser(req, res) {
const followUser = { userId: req.params.userId, followedBy: req.user.id };
Follower.create(followUser)
.then(() => res.status(201).json({ status: 201, message: ` Thank you for following ${req.userInfo.username}.` }));
Expand All @@ -24,7 +24,7 @@ class FollowerController {
* @param {Object} res
* @return {Object} message
*/
static unfollow(req, res) {
unfollowUser(req, res) {
Follower.destroy({ where: { userId: req.params.userId, followedBy: req.user.id } })
.then(() => res.status(200).json({ status: 200, message: ' unfollowed successfully.' }));
}
Expand All @@ -35,7 +35,7 @@ class FollowerController {
* @param {Object} res getting followers
* @returns {Object} followers and number of followers
*/
static followers(req, res) {
getFollowers(req, res) {
Follower.findAll({
where: { userId: req.user.id },
include: [{
Expand All @@ -60,7 +60,7 @@ class FollowerController {
* @param {Object} res
* @return {Object} following people and number of following
*/
static following(req, res) {
getFollowing(req, res) {
Follower.findAll({
where: { followedBy: req.user.id },
include: [{
Expand Down
8 changes: 4 additions & 4 deletions controllers/highlightText.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { articleHighlights, user, article } = models;
* @exports
* @class
*/
class HighlightText {
class Highlights {
/**
* create a highlighted article section
* @param {object} req - User's request
Expand Down Expand Up @@ -42,7 +42,7 @@ class HighlightText {
* @param {object} res - Response's holder
* @returns {object} Response
*/
async getArticleHighlightTexts(req, res) {
async getArticleHighlightedTexts(req, res) {
const { articleId } = req.params;
const userId = req.user.id;
const highlightedTexts = await articleHighlights.findAll({
Expand All @@ -63,7 +63,7 @@ class HighlightText {
* @param {object} res - Response's holder
* @returns {object} Response
*/
async updateHighlightText(req, res) {
async updateHighlightedText(req, res) {
const userId = req.user.id;
const { articleId, highlightId } = req.params;
const {
Expand Down Expand Up @@ -100,4 +100,4 @@ class HighlightText {
}
}

export default new HighlightText();
export default Highlights;
16 changes: 8 additions & 8 deletions controllers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NotificationController {
* @param {Integer} notifier -notifier id
* @returns {Object} Create notifications
*/
async createFavorite(articleId, message, notifier) {
async createNotificationForFavorite(articleId, message, notifier) {
try {
let notifications = [];
const usersWhoFavoritedArticle = await Check.checkWhoFavoritesArticle(articleId);
Expand Down Expand Up @@ -64,7 +64,7 @@ class NotificationController {
* @param {Integer} notifier -notifier id
* @returns {Object} Create notifications
*/
async createFollower(folloewerId, message) {
async createNotificationForFollower(folloewerId, message) {
try {
const notifications = [];
const notification = { userId: '', message: '' };
Expand Down Expand Up @@ -94,7 +94,7 @@ class NotificationController {
* @param {Integer} notifier -notifier id
* @returns {Object} send notifications
*/
async sendFavorite(articleId, message, notifier) {
async sendNotificationToFavorites(articleId, message, notifier) {
const emails = new Set();
const usersWhoFavoritedArticle = await Check.checkWhoFavoritesArticle(articleId);
if (usersWhoFavoritedArticle.length > 0) {
Expand Down Expand Up @@ -123,7 +123,7 @@ class NotificationController {
* @param {Integer} notifier -notifier id
* @returns {Object} send notifications
*/
async sendFollower(followerId, message) {
async sendNotificationToFollower(followerId, message) {
const emails = new Set();
const followers = await Check.checkFollowers(followerId);
if (followers.length > 0) {
Expand All @@ -150,7 +150,7 @@ class NotificationController {
* @param {Object} res response object
* @returns {Object} result
*/
async getAll(req, res) {
async getAllNotifications(req, res) {
try {
const notifications = await Notification.findAll({
where: { userId: req.user.id, status: 'unread' },
Expand All @@ -168,7 +168,7 @@ class NotificationController {
* @param {Object} res response object
* @returns {Object} result
*/
async getOne(req, res) {
async getSingleNotification(req, res) {
try {
const id = parseInt(req.params.id, 10);
const notification = await Notification.findOne({
Expand All @@ -193,7 +193,7 @@ class NotificationController {
* @param {Object} res response object
* @returns {Object} result
*/
async delete(req, res) {
async deleteNotification(req, res) {
try {
const id = parseInt(req.params.id, 10);
const notification = await Notification.destroy({
Expand Down Expand Up @@ -239,4 +239,4 @@ class NotificationController {
}
}

export default new NotificationController();
export default NotificationController;
4 changes: 2 additions & 2 deletions controllers/rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Rate {
* @param {object} res - response
* @return {object} response
*/
static async rateArticle(req, res) {
async rateArticle(req, res) {
const userId = req.user.id;
const { articleId } = req.params;
const rating = parseInt(req.body.rating, 10);
Expand All @@ -41,7 +41,7 @@ class Rate {
* @param {object} res - response
* @return {object} response
*/
static async getArticleRate(req, res) {
async getArticleRatings(req, res) {
let page, limit;
if (Object.keys(req.query).length === 0) {
page = 1; limit = 20;
Expand Down
Loading

0 comments on commit d4444a7

Please sign in to comment.