const validatorsVideos = {
videosAdd,
+ videosUpdate,
videosGet,
videosRemove,
videosSearch
})
}
-function videosGet (req, res, next) {
+function videosUpdate (req, res, next) {
req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
+ req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
+ req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
+ req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
- logger.debug('Checking videosGet parameters', { parameters: req.params })
+ logger.debug('Checking videosUpdate parameters', { parameters: req.body })
checkErrors(req, res, function () {
- db.Video.load(req.params.id, function (err, video) {
- if (err) {
- logger.error('Error in videosGet request validator.', { error: err })
- return res.sendStatus(500)
- }
+ checkVideoExists(req.params.id, res, next)
+ })
+}
- if (!video) return res.status(404).send('Video not found')
+function videosGet (req, res, next) {
+ req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
- next()
- })
+ logger.debug('Checking videosGet parameters', { parameters: req.params })
+
+ checkErrors(req, res, function () {
+ checkVideoExists(req.params.id, res, next)
})
}
// ---------------------------------------------------------------------------
module.exports = validatorsVideos
+
+// ---------------------------------------------------------------------------
+
+function checkVideoExists (id, res, callback) {
+ db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) {
+ if (err) {
+ logger.error('Error in video request validator.', { error: err })
+ return res.sendStatus(500)
+ }
+
+ if (!video) return res.status(404).send('Video not found')
+
+ res.locals.video = video
+ callback()
+ })
+}