lib/class/Field.js
function _createValidate (type, defaultValidate = {}, customValidate) {
  if (customValidate === null) { return null }
  let val = {}
  if (type.key === 'STRING')   { val = { len: [0, type.options.length] } }
  if (type.key === 'TEXT')     { val = { len: [0, 2147483647] } }
  if (type.key === 'INTEGER')  { val = { isInt: true, min: -2147483647, max: 2147483647 } }
  if (type.key === 'FLOAT')    { val = { isFloat: true, min: -1E+308, max: 1E+308 } }
  if (type.key === 'ENUM')     { val = { isIn: [type.values] } }
  if (type.key === 'BOOLEAN')  { val = { isBoolean: true } }
  if (type.key === 'DATE')     { val = { isDate: true } }
  if (type.key === 'DATEONLY') { val = { isDate: true } }
  if (type.key === 'TIME')     { val = { isTime: _isTimeValidate() } }
  if (type.key === 'JSON')     { val = { isJson: _isJsonValidate() } }
  if (type.key === 'JSONB')    { val = { isJson: _isJsonValidate() } }
  if (type.key === 'UUID')     { val = { isUUID: 4 } }
  if (type.key === 'ARRAY')    { val = { isArray: _isArrayValidate(type.type) } }
  const FIELD = { validate: Object.assign(Object.assign(val, defaultValidate), customValidate) }
  _normalizeValidate(FIELD)
  return FIELD.validate
}
function _createValidate (type, defaultValidate = {}, customValidate) {
  if (customValidate === null) { return null }
  let val = {}
  if (type.key === 'STRING')   { val = { len: [0, type.options.length] } }
  if (type.key === 'TEXT')     { val = { len: [0, 2147483647] } }
  if (type.key === 'INTEGER')  { val = { isInt: true, min: -2147483647, max: 2147483647 } }
  if (type.key === 'FLOAT')    { val = { isFloat: true, min: -1E+308, max: 1E+308 } }
  if (type.key === 'ENUM')     { val = { isIn: [type.values] } }
  if (type.key === 'BOOLEAN')  { val = { isBoolean: true } }
  if (type.key === 'DATE')     { val = { isDate: true } }
  if (type.key === 'DATEONLY') { val = { isDate: true } }
  if (type.key === 'TIME')     { val = { isTime: _isTimeValidate() } }
  if (type.key === 'JSON')     { val = { isJson: _isJsonValidate() } }
  if (type.key === 'JSONB')    { val = { isJson: _isJsonValidate() } }
  if (type.key === 'UUID')     { val = { isUUID: 4 } }
  if (type.key === 'ARRAY')    { val = { isArray: _isArrayValidate(type.type) } }
  const FIELD = { validate: Object.assign(Object.assign(val, defaultValidate), customValidate) }
  _normalizeValidate(FIELD)
  return FIELD.validate
}
function _createValidate ( type , defaultValidate = { } , customValidate ) { if ( customValidate === null ) { return null } let val = { } if ( type . key === 'STRING' ) { val = { len : [ 0 , type . options . length ] } } if ( type . key === 'TEXT' ) { val = { len : [ 0 , 2147483647 ] } } if ( type . key === 'INTEGER' ) { val = { isInt : true , min : - 2147483647 , max : 2147483647 } } if ( type . key === 'FLOAT' ) { val = { isFloat : true , min : - 1E+308 , max : 1E+308 } } if ( type . key === 'ENUM' ) { val = { isIn : [ type . values ] } } if ( type . key === 'BOOLEAN' ) { val = { isBoolean : true } } if ( type . key === 'DATE' ) { val = { isDate : true } } if ( type . key === 'DATEONLY' ) { val = { isDate : true } } if ( type . key === 'TIME' ) { val = { isTime : _isTimeValidate ( ) } } if ( type . key === 'JSON' ) { val = { isJson : _isJsonValidate ( ) } } if ( type . key === 'JSONB' ) { val = { isJson : _isJsonValidate ( ) } } if ( type . key === 'UUID' ) { val = { isUUID : 4 } } if ( type . key === 'ARRAY' ) { val = { isArray : _isArrayValidate ( type . type ) } } const FIELD = { validate : Object . assign ( Object . assign ( val , defaultValidate ) , customValidate ) } _normalizeValidate ( FIELD ) return FIELD . validate }
Devuelve un objeto validate.
@param {!SequelizeType} type              - Propiedad tipo del atributo de un modelo sequelize.
@param {Object}         [defaultValidate] - Propiedad validate por defecto.
@param {Object}         [customValidate]  - Propiedad validate personalizado.
@return {Object}
Devuelve un objeto validate .