fix validation
This commit is contained in:
parent
8a725a54f1
commit
15cc0dc975
1 changed files with 16 additions and 27 deletions
|
|
@ -32,7 +32,7 @@ function allMachineScopes (machineList, machineScope) {
|
|||
return machineScopes
|
||||
}
|
||||
|
||||
function satisfiesRequireAny (config, cryptos, machineList, field, refFields) {
|
||||
function satisfiesRequire (config, cryptos, machineList, field, anyFields, allFields) {
|
||||
const fieldCode = field.code
|
||||
|
||||
const scopes = allScopes(
|
||||
|
|
@ -41,37 +41,24 @@ function satisfiesRequireAny (config, cryptos, machineList, field, refFields) {
|
|||
)
|
||||
|
||||
return scopes.every(scope => {
|
||||
const isEnabled = () => refFields.some(refField => {
|
||||
const isAnyEnabled = () => _.some(refField => {
|
||||
return isScopeEnabled(config, cryptos, machineList, refField, scope)
|
||||
})
|
||||
}, anyFields)
|
||||
|
||||
const areAllEnabled = () => _.every(refField => {
|
||||
return isScopeEnabled(config, cryptos, machineList, refField, scope)
|
||||
}, allFields)
|
||||
|
||||
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
|
||||
const isRequired = refFields.length === 0 || isEnabled()
|
||||
const isRequired = (_.isEmpty(anyFields) || isAnyEnabled()) &&
|
||||
(_.isEmpty(allFields) || areAllEnabled())
|
||||
|
||||
const isValid = isRequired ? !isBlank : true
|
||||
|
||||
return isValid
|
||||
})
|
||||
if (!isValid) {
|
||||
pp('DEBUG103')({fieldCode, isBlank, isRequired})
|
||||
}
|
||||
|
||||
function satisfiesRequireAll (config, cryptos, machineList, field, refFields) {
|
||||
const fieldCode = field.code
|
||||
|
||||
const scopes = allScopes(
|
||||
allCryptoScopes(cryptos, field.cryptoScope),
|
||||
allMachineScopes(machineList, field.machineScope)
|
||||
)
|
||||
|
||||
return scopes.every(scope => {
|
||||
const isEnabled = () => _.isEmpty(refFields) || refFields.every(refField => {
|
||||
return isScopeEnabled(config, cryptos, machineList, refField, scope)
|
||||
})
|
||||
|
||||
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
|
||||
const isRequired = refFields.length === 0 || isEnabled()
|
||||
|
||||
const isValid = isRequired ? !isBlank : true
|
||||
|
||||
return isValid
|
||||
})
|
||||
}
|
||||
|
|
@ -161,6 +148,8 @@ function ensureConstraints (config) {
|
|||
})
|
||||
}
|
||||
|
||||
const pp = require('./pp')
|
||||
|
||||
function validateRequires (config) {
|
||||
return fetchMachines()
|
||||
.then(machineList => {
|
||||
|
|
@ -174,9 +163,9 @@ function validateRequires (config) {
|
|||
|
||||
const refFieldsAny = _.map(_.partial(getField, group), field.enabledIfAny)
|
||||
const refFieldsAll = _.map(_.partial(getField, group), field.enabledIfAll)
|
||||
const isInvalid = !satisfiesRequire(config, cryptos, machineList, field, refFieldsAny, refFieldsAll)
|
||||
|
||||
return !satisfiesRequireAny(config, cryptos, machineList, field, refFieldsAny) &&
|
||||
!satisfiesRequireAll(config, cryptos, machineList, field, refFieldsAll)
|
||||
return isInvalid
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue