From d38b82810638b9f664c9016fac2684454c273a77 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Mar 2017 21:35:43 +0100 Subject: Add like/dislike system for videos --- server/middlewares/validators/users.js | 22 +++++++++++++++++++++- server/middlewares/validators/videos.js | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators') 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') const validatorsUsers = { usersAdd, usersRemove, - usersUpdate + usersUpdate, + usersVideoRating } function usersAdd (req, res, next) { @@ -62,6 +63,25 @@ function usersUpdate (req, res, next) { checkErrors(req, res, next) } +function usersVideoRating (req, res, next) { + req.checkParams('videoId', 'Should have a valid video id').notEmpty().isUUID(4) + + logger.debug('Checking usersVideoRating parameters', { parameters: req.params }) + + checkErrors(req, res, function () { + db.Video.load(req.params.videoId, function (err, video) { + if (err) { + logger.error('Error in user request validator.', { error: err }) + return res.sendStatus(500) + } + + if (!video) return res.status(404).send('Video not found') + + next() + }) + }) +} + // --------------------------------------------------------------------------- module.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 = { videosRemove, videosSearch, - videoAbuseReport + videoAbuseReport, + + videoRate } function videosAdd (req, res, next) { @@ -119,6 +121,17 @@ function videoAbuseReport (req, res, next) { }) } +function videoRate (req, res, next) { + req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) + req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() + + logger.debug('Checking videoRate parameters', { parameters: req.body }) + + checkErrors(req, res, function () { + checkVideoExists(req.params.id, res, next) + }) +} + // --------------------------------------------------------------------------- module.exports = validatorsVideos -- cgit v1.2.3