Skip to content

Commit

Permalink
fix: empty value validation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 committed Dec 6, 2023
1 parent f62dff6 commit 85dcc3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
17 changes: 7 additions & 10 deletions src/screens/HyperSwitch/Routing/RoutingUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,10 @@ let checkIfValuePresent = dict => {
ele != ""->Js.Json.string
})
->Js.Array2.length > 0 ||
valueFromObject->getString("value", "") !== "" ||
valueFromObject->getFloat("value", -1.0) !== -1.0
valueFromObject->getString("value", "")->Js.String2.length > 0 ||
valueFromObject->getFloat("value", -1.0) !== -1.0 ||
(valueFromObject->getDictfromDict("value")->getString("key", "")->Js.String2.length > 0 &&
valueFromObject->getDictfromDict("value")->getString("value", "")->Js.String2.length > 0)
}
let validateConditionJsonFor3ds = json => {
switch json->Js.Json.decodeObject {
Expand All @@ -715,17 +717,12 @@ let validateConditions = dict => {
->Js.Array2.every(MakeRuleFieldComponent.validateConditionJson)
}

let validateConditionsEvenIfOneExists = dict => {
let validateConditionsFor3ds = dict => {
let conditionsArray = dict->LogicUtils.getArrayFromDict("statements", [])
let vector = Js.Vector.make(conditionsArray->Js.Array2.length, false)

conditionsArray->Array.forEachWithIndex((value, index) => {
let res = value->validateConditionJsonFor3ds
vector->Js.Vector.set(index, res)
conditionsArray->Array.every(value => {
value->validateConditionJsonFor3ds
})

let _result = Js.Vector.filterInPlace((. val) => val == true, vector)
vector
}

let filterEmptyValues = (arr: array<RoutingTypes.condition>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,13 @@ let validateStatements = statementsArray => {
statementsArray->Js.Array2.every(isStatementMandatoryFieldsPresent)
}

let initialValueForStatement: AdvancedRoutingTypes.statementSendType = {
condition: [],
}

let generateStatements = statements => {
open LogicUtils

let initialValueForStatement: AdvancedRoutingTypes.statementSendType = {
condition: [],
}

statements->Array.reduce([initialValueForStatement], (acc, statement) => {
let statementDict = statement->getDictFromJsonObject
let logicalOperator = statementDict->getString("logical", "")->Js.String2.toLowerCase
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/ThreeDSFlow/HSwitchThreeDS.res
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ let make = () => {
} else {
rules->Array.forEachWithIndex((rule, i) => {
let ruleDict = rule->LogicUtils.getDictFromJsonObject
if RoutingUtils.validateConditionsEvenIfOneExists(ruleDict)->Js.Array2.length == 0 {
if !RoutingUtils.validateConditionsFor3ds(ruleDict) {
errors->Js.Dict.set(
`Rule ${(i + index)->string_of_int} - Condition`,
`Rule ${(i + 1)->string_of_int} - Condition`,
`Invalid`->Js.Json.string,
)
}
Expand Down

0 comments on commit 85dcc3d

Please sign in to comment.