From 757013690877ec49b31e7dcb6a6869f9ee3b50bb Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 17 Oct 2020 21:57:22 +0530 Subject: [PATCH] Changes validations --- utils/validations.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/validations.js b/utils/validations.js index 57767769a..ad32d88e1 100644 --- a/utils/validations.js +++ b/utils/validations.js @@ -1,17 +1,19 @@ const R = require('ramda'); const { VALID_RECORD_TYPES } = require('./constants'); const { or, and, validate, between, testRegex } = require('./helpers'); +const withLengthGte = n => R.compose(R.gte(R.__, n), R.length); +const withLengthEq = n => R.compose(R.equals(n), R.length); const validateCnameRecord = key => and([ R.propSatisfies(R.is(String), key), - R.compose(R.equals(1), R.length, R.reject(R.equals('URL')), R.keys), - R.propSatisfies(R.compose(R.gte(R.__, 3), R.length), key), + R.compose(withLengthEq(1), R.reject(R.equals('URL')), R.keys), + R.propSatisfies(withLengthGte(3), key), R.propSatisfies(R.complement(testRegex(/^https?:\/\//ig)), key), ]); const validateARecord = key => and([ - R.compose(R.equals(1), R.length, R.keys), - R.propSatisfies(R.compose(R.gte(R.__, 1), R.length), key), + R.compose(withLengthEq(1), R.keys), + R.propSatisfies(withLengthGte(1), key), ]); const validateDomainData = validate({ @@ -33,7 +35,7 @@ const validateDomainData = validate({ R.is(Object), R.complement(R.isEmpty), R.where({ - username: R.is(String), + username: and([ R.is(String), withLengthGte(1) ]), email: R.is(String), }), ]),