1 import * as express from 'express'
2 import 'express-validator'
3 import { body, param } from 'express-validator/check'
4 import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5 import { isVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
6 import { logger } from '../../../helpers/logger'
7 import { areValidationErrors } from '../utils'
8 import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9 import { VideoRateType } from '../../../../shared/models/videos'
10 import { isAccountNameValid } from '../../../helpers/custom-validators/accounts'
12 const videoUpdateRateValidator = [
13 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
14 body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'),
16 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
17 logger.debug('Checking videoRate parameters', { parameters: req.body })
19 if (areValidationErrors(req, res)) return
20 if (!await isVideoExist(req.params.id, res)) return
26 const getAccountVideoRateValidator = function (rateType: VideoRateType) {
28 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
29 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
31 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
32 logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
34 if (areValidationErrors(req, res)) return
36 const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, req.params.videoId)
38 return res.status(404)
39 .json({ error: 'Video rate not found' })
43 res.locals.accountVideoRate = rate
50 // ---------------------------------------------------------------------------
53 videoUpdateRateValidator,
54 getAccountVideoRateValidator