aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers/customValidators.js
blob: c433e5c5d92532b0ab77fdef4e400e9c6657548a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;(function () {
  'use strict'

  var validator = require('validator')

  var customValidators = {
    eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
    eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
    isArray: isArray
  }

  function eachIsRemoteVideosAddValid (values) {
    return values.every(function (val) {
      return validator.isLength(val.name, 1, 50) &&
        validator.isLength(val.description, 1, 50) &&
        validator.isLength(val.magnetUri, 10) &&
        validator.isURL(val.podUrl)
    })
  }

  function eachIsRemoteVideosRemoveValid (values) {
    return values.every(function (val) {
      return validator.isLength(val.magnetUri, 10)
    })
  }

  function isArray (value) {
    return Array.isArray(value)
  }

  // ---------------------------------------------------------------------------

  module.exports = customValidators
})()