aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
commitd38b82810638b9f664c9016fac2684454c273a77 (patch)
tree9465c367e5033675309efca4d66790c6fdd5230d /server/middlewares/validators
parent8f9064432122cba0f518a24ac4378357dadec589 (diff)
downloadPeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.gz
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.zst
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.zip
Add like/dislike system for videos
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/users.js22
-rw-r--r--server/middlewares/validators/videos.js15
2 files changed, 35 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.js b/server/middlewares/validators/users.js
index 3089370ff..ce83fc074 100644
--- a/server/middlewares/validators/users.js
+++ b/server/middlewares/validators/users.js
@@ -7,7 +7,8 @@ const logger = require('../../helpers/logger')
7const validatorsUsers = { 7const validatorsUsers = {
8 usersAdd, 8 usersAdd,
9 usersRemove, 9 usersRemove,
10 usersUpdate 10 usersUpdate,
11 usersVideoRating
11} 12}
12 13
13function usersAdd (req, res, next) { 14function usersAdd (req, res, next) {
@@ -62,6 +63,25 @@ function usersUpdate (req, res, next) {
62 checkErrors(req, res, next) 63 checkErrors(req, res, next)
63} 64}
64 65
66function usersVideoRating (req, res, next) {
67 req.checkParams('videoId', 'Should have a valid video id').notEmpty().isUUID(4)
68
69 logger.debug('Checking usersVideoRating parameters', { parameters: req.params })
70
71 checkErrors(req, res, function () {
72 db.Video.load(req.params.videoId, function (err, video) {
73 if (err) {
74 logger.error('Error in user request validator.', { error: err })
75 return res.sendStatus(500)
76 }
77
78 if (!video) return res.status(404).send('Video not found')
79
80 next()
81 })
82 })
83}
84
65// --------------------------------------------------------------------------- 85// ---------------------------------------------------------------------------
66 86
67module.exports = validatorsUsers 87module.exports = validatorsUsers
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index 5c3f3ecf3..7dc79c56f 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -13,7 +13,9 @@ const validatorsVideos = {
13 videosRemove, 13 videosRemove,
14 videosSearch, 14 videosSearch,
15 15
16 videoAbuseReport 16 videoAbuseReport,
17
18 videoRate
17} 19}
18 20
19function videosAdd (req, res, next) { 21function videosAdd (req, res, next) {
@@ -119,6 +121,17 @@ function videoAbuseReport (req, res, next) {
119 }) 121 })
120} 122}
121 123
124function videoRate (req, res, next) {
125 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
126 req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid()
127
128 logger.debug('Checking videoRate parameters', { parameters: req.body })
129
130 checkErrors(req, res, function () {
131 checkVideoExists(req.params.id, res, next)
132 })
133}
134
122// --------------------------------------------------------------------------- 135// ---------------------------------------------------------------------------
123 136
124module.exports = validatorsVideos 137module.exports = validatorsVideos