+ return next()
+ }
+]
+
+const usersUpdateMeValidator = [
+ body('description').optional().custom(isUserDescriptionValid).withMessage('Should have a valid description'),
+ body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'),
+ body('email').optional().isEmail().withMessage('Should have a valid email attribute'),
+ body('displayNSFW').optional().custom(isUserDisplayNSFWValid).withMessage('Should have a valid display Not Safe For Work attribute'),
+ body('autoPlayVideo').optional().custom(isUserAutoPlayVideoValid).withMessage('Should have a valid automatically plays video attribute'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ // TODO: Add old password verification
+ logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') })
+
+ if (areValidationErrors(req, res)) return
+
+ return next()
+ }
+]
+
+const usersUpdateMyAvatarValidator = [
+ body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
+ 'This file is not supported. Please, make sure it is of the following type : '
+ + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ')
+ ),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files })
+
+ if (areValidationErrors(req, res)) return
+
+ const imageFile = req.files['avatarfile'][0] as Express.Multer.File
+ if (imageFile.size > CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max) {
+ res.status(400)
+ .send({ error: `The size of the avatar is too big (>${CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max}).` })
+ .end()
+ return
+ }
+
+ return next()
+ }
+]
+
+const usersGetValidator = [
+ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersGet parameters', { parameters: req.params })
+
+ if (areValidationErrors(req, res)) return
+ if (!await checkUserIdExist(req.params.id, res)) return
+
+ return next()
+ }
+]
+
+const usersVideoRatingValidator = [
+ param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
+
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking usersVideoRating parameters', { parameters: req.params })