diff options
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.js | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js index ee68ebc10..2e9cf822e 100644 --- a/server/helpers/custom-validators/remote/videos.js +++ b/server/helpers/custom-validators/remote/videos.js | |||
@@ -1,5 +1,7 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const has = require('lodash/has') | ||
4 | |||
3 | const constants = require('../../../initializers/constants') | 5 | const constants = require('../../../initializers/constants') |
4 | const videosValidators = require('../videos') | 6 | const videosValidators = require('../videos') |
5 | const miscValidators = require('../misc') | 7 | const miscValidators = require('../misc') |
@@ -7,7 +9,8 @@ const miscValidators = require('../misc') | |||
7 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] | 9 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] |
8 | 10 | ||
9 | const remoteVideosValidators = { | 11 | const remoteVideosValidators = { |
10 | isEachRemoteRequestVideosValid | 12 | isEachRemoteRequestVideosValid, |
13 | isEachRemoteRequestVideosQaduValid | ||
11 | } | 14 | } |
12 | 15 | ||
13 | function isEachRemoteRequestVideosValid (requests) { | 16 | function isEachRemoteRequestVideosValid (requests) { |
@@ -16,13 +19,13 @@ function isEachRemoteRequestVideosValid (requests) { | |||
16 | const video = request.data | 19 | const video = request.data |
17 | return ( | 20 | return ( |
18 | isRequestTypeAddValid(request.type) && | 21 | isRequestTypeAddValid(request.type) && |
19 | isCommonVideoAttrbiutesValid(video) && | 22 | isCommonVideoAttributesValid(video) && |
20 | videosValidators.isVideoAuthorValid(video.author) && | 23 | videosValidators.isVideoAuthorValid(video.author) && |
21 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) | 24 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) |
22 | ) || | 25 | ) || |
23 | ( | 26 | ( |
24 | isRequestTypeUpdateValid(request.type) && | 27 | isRequestTypeUpdateValid(request.type) && |
25 | isCommonVideoAttrbiutesValid(video) | 28 | isCommonVideoAttributesValid(video) |
26 | ) || | 29 | ) || |
27 | ( | 30 | ( |
28 | isRequestTypeRemoveValid(request.type) && | 31 | isRequestTypeRemoveValid(request.type) && |
@@ -37,13 +40,27 @@ function isEachRemoteRequestVideosValid (requests) { | |||
37 | }) | 40 | }) |
38 | } | 41 | } |
39 | 42 | ||
43 | function isEachRemoteRequestVideosQaduValid (requests) { | ||
44 | return miscValidators.isArray(requests) && | ||
45 | requests.every(function (request) { | ||
46 | const video = request.data | ||
47 | |||
48 | return ( | ||
49 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
50 | (has(video, 'views') === false || videosValidators.isVideoViewsValid) && | ||
51 | (has(video, 'likes') === false || videosValidators.isVideoLikesValid) && | ||
52 | (has(video, 'dislikes') === false || videosValidators.isVideoDislikesValid) | ||
53 | ) | ||
54 | }) | ||
55 | } | ||
56 | |||
40 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
41 | 58 | ||
42 | module.exports = remoteVideosValidators | 59 | module.exports = remoteVideosValidators |
43 | 60 | ||
44 | // --------------------------------------------------------------------------- | 61 | // --------------------------------------------------------------------------- |
45 | 62 | ||
46 | function isCommonVideoAttrbiutesValid (video) { | 63 | function isCommonVideoAttributesValid (video) { |
47 | return videosValidators.isVideoDateValid(video.createdAt) && | 64 | return videosValidators.isVideoDateValid(video.createdAt) && |
48 | videosValidators.isVideoDateValid(video.updatedAt) && | 65 | videosValidators.isVideoDateValid(video.updatedAt) && |
49 | videosValidators.isVideoDescriptionValid(video.description) && | 66 | videosValidators.isVideoDescriptionValid(video.description) && |