diff options
author | Yohan Boniface <yohanboniface@free.fr> | 2019-04-09 11:02:02 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-04-09 11:02:02 +0200 |
commit | c100a6142e6571312db9f6407698a21a08b593fb (patch) | |
tree | c80ac9c7754b8f5b133255e003557937e415ee23 /server/middlewares/validators/videos | |
parent | 8ce1ba6e3efe0a688d6a0b57e8201cde33ad7aac (diff) | |
download | PeerTube-c100a6142e6571312db9f6407698a21a08b593fb.tar.gz PeerTube-c100a6142e6571312db9f6407698a21a08b593fb.tar.zst PeerTube-c100a6142e6571312db9f6407698a21a08b593fb.zip |
Add /accounts/:username/ratings endpoint (#1756)
* Add /users/me/videos/ratings endpoint
* Move ratings endpoint from users to accounts
* /accounts/:name/ratings: add support for rating= and sort=
* Restrict ratings list to owner
* Wording and better way to ensure current account
Diffstat (limited to 'server/middlewares/validators/videos')
-rw-r--r-- | server/middlewares/validators/videos/video-rates.ts | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts index 280385912..e79d80e97 100644 --- a/server/middlewares/validators/videos/video-rates.ts +++ b/server/middlewares/validators/videos/video-rates.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' | 4 | import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' |
5 | import { isRatingValid } from '../../../helpers/custom-validators/video-rates' | ||
5 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' | 6 | import { doesVideoExist, isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | 7 | import { logger } from '../../../helpers/logger' |
7 | import { areValidationErrors } from '../utils' | 8 | import { areValidationErrors } from '../utils' |
@@ -47,9 +48,22 @@ const getAccountVideoRateValidator = function (rateType: VideoRateType) { | |||
47 | ] | 48 | ] |
48 | } | 49 | } |
49 | 50 | ||
51 | const videoRatingValidator = [ | ||
52 | query('rating').optional().custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), | ||
53 | |||
54 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
55 | logger.debug('Checking rating parameter', { parameters: req.params }) | ||
56 | |||
57 | if (areValidationErrors(req, res)) return | ||
58 | |||
59 | return next() | ||
60 | } | ||
61 | ] | ||
62 | |||
50 | // --------------------------------------------------------------------------- | 63 | // --------------------------------------------------------------------------- |
51 | 64 | ||
52 | export { | 65 | export { |
53 | videoUpdateRateValidator, | 66 | videoUpdateRateValidator, |
54 | getAccountVideoRateValidator | 67 | getAccountVideoRateValidator, |
68 | videoRatingValidator | ||
55 | } | 69 | } |