-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from andela/ft-get-read-time-166790104
#166790104 implement readtime on article create and update
- Loading branch information
Showing
21 changed files
with
436 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
service_name: travis-pro | ||
repo_token: 5wHJgqAVMocmuMfz7Nr26hEBqmO7gtzJJ | ||
repo_token: G3KUaGgIQZdYITPWuU0uIfjZckwOlOq8C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* eslint-disable require-jsdoc */ | ||
import Sequelize from 'sequelize'; | ||
import model from '../../models'; | ||
|
||
const { Op } = Sequelize; | ||
|
||
const { LikeAndDislike, Comments } = model; | ||
|
||
const findOneComment = async (commentId) => { | ||
const foundComment = await Comments.findOne({ where: { id: commentId } }); | ||
|
||
return foundComment; | ||
}; | ||
|
||
const userLikedOrDiskedComment = async (id, commentId) => { | ||
const userReacted = await LikeAndDislike.findAll({ where: { userId: id, | ||
commentId } }); | ||
|
||
return userReacted; | ||
}; | ||
|
||
const findDislikedComment = async (id, commentId) => { | ||
const unlikedArticle = await LikeAndDislike.findAll({ where: { userId: id, | ||
commentId, | ||
[Op.or]: [{ likes: false }, { dislikes: true }] } }); | ||
|
||
return unlikedArticle; | ||
}; | ||
|
||
const findLikedComment = async (id, commentId) => { | ||
const unlikedArticle = await LikeAndDislike.findAll({ where: { userId: id, | ||
commentId, | ||
[Op.or]: [{ dislikes: false }, { likes: true }] } }); | ||
|
||
return unlikedArticle; | ||
}; | ||
|
||
const findDisliked = async (id, commentId) => { | ||
const disliked = await LikeAndDislike.findAll({ where: { userId: id, | ||
commentId, | ||
dislikes: true } }); | ||
|
||
return disliked; | ||
}; | ||
|
||
const ChangeFromDislikeToLike = async (dislikeId) => { | ||
const updateFromDislikeToLike = await LikeAndDislike.update({ dislikes: false, likes: true }, | ||
{ where: { id: dislikeId } }); | ||
|
||
return updateFromDislikeToLike; | ||
}; | ||
|
||
const ChangeFromLikeToDisLike = async (dislikeId) => { | ||
const updateFromDislikeToLike = await LikeAndDislike.update({ dislikes: true, likes: false }, | ||
{ where: { id: dislikeId } }); | ||
|
||
return updateFromDislikeToLike; | ||
}; | ||
|
||
const findCommentLikes = async (id, commentId) => { | ||
const liked = await LikeAndDislike.findAll({ where: { userId: id, | ||
commentId, | ||
likes: true } }); | ||
|
||
return liked; | ||
}; | ||
|
||
const undoLikeOrDislikeComments = async (commentLike) => { | ||
const unlikeComment = await LikeAndDislike.update({ likes: false, dislikes: false }, | ||
{ where: { id: commentLike } }); | ||
|
||
return unlikeComment; | ||
}; | ||
|
||
const countCommentLikes = async (commentId) => { | ||
const likes = await LikeAndDislike.count({ where: { commentId, | ||
likes: true } }); | ||
|
||
return likes; | ||
}; | ||
|
||
const countCommentDislikes = async (commentId) => { | ||
const dislikes = await LikeAndDislike.count({ where: { commentId, | ||
dislikes: true } }); | ||
|
||
return dislikes; | ||
}; | ||
|
||
export { | ||
countCommentDislikes, | ||
countCommentLikes, | ||
undoLikeOrDislikeComments, | ||
findCommentLikes, | ||
ChangeFromLikeToDisLike, | ||
ChangeFromDislikeToLike, | ||
findDisliked, | ||
findLikedComment, | ||
findDislikedComment, | ||
userLikedOrDiskedComment, | ||
findOneComment | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const converter = seconds => ((seconds > 60) ? `${Math.ceil(seconds / 60)} min` : 'Less than a minute'); | ||
|
||
const readTime = (body) => { | ||
const numWords = w => w.split(' ').length; | ||
const WPS = 4; | ||
const words = numWords(body); | ||
const sec = words / WPS; | ||
return converter(sec); | ||
}; | ||
export default readTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.