-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rating(paginating) paginate and refactor rating
[Starts #167313406]
- Loading branch information
1 parent
f35b173
commit ab52873
Showing
9 changed files
with
302 additions
and
245 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
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,26 @@ | ||
import Util from '../helpers/util'; | ||
import models from '../models/index'; | ||
|
||
const util = new Util(); | ||
|
||
export default async (req, res, next) => { | ||
try { | ||
const ArticleSlug = req.params.articleSlug; | ||
const post = await models.Article.findOne({ where: { slug: ArticleSlug } }); | ||
|
||
if (!post) { | ||
util.setError(404, 'post not found'); | ||
return util.send(res); | ||
} | ||
const user = await models.user.findOne({ where: { email: req.auth.email } }); | ||
const userId = user.id; | ||
if (userId === post.authorId) { | ||
util.setError(400, 'You cannot rate your own article'); | ||
return util.send(res); | ||
} | ||
next(); | ||
} catch (error) { | ||
util.setError(500, 'server error contact admin'); | ||
return util.send(res); | ||
} | ||
}; |
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
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.