update index.js and util.js

main
MohammadHoseinPaymard 2 weeks ago
parent 31fc9dc5de
commit eaf02824ff
  1. 2
      index.js
  2. 109
      util.js

@ -100,7 +100,7 @@ require(path.join(process.cwd(), "..", "server", "dist", "database.js"));
console.log("allWorkFlowInfo", JSON.stringify(allWorkFlowInfo, null, 2));
fs.writeFileSync("./result-pretty.json", JSON.stringify(allWorkFlowInfo, null, 2));
console.timeEnd("WorkflowTester")
console.timeEnd("WorkflowTester");
console.log("DONE");
process.exit(0);
})()

@ -12,6 +12,115 @@ function convertStringToJson(string) {
return {};
}
}
function checkingOptions({ question, answer }) {
let options = convertStringToJson(question?.options) || [],
inputType = +question?.inputType || -1;
// console.log("options", options)
if (!Array.isArray(options)) options = [options];
const OptionsValidValue = options.map((option) => {
return parseValue(option?.value);
})
const questionAnswer = answer[question.id];
if (questionAnswer === null || questionAnswer === undefined) return {
ok: false
}
switch (inputType) {
case 1: //TEXT
case 3:
if (typeof questionAnswer !== "string" || questionAnswer.length == 0) {
return {
ok: false
}
}
break;
case 2: //NUMBER
if (!isNumber(questionAnswer) || !OptionsValidValue.includes(questionAnswer?.toString())) {
return {
ok: false
}
}
break;
case 4: // tak entekhab
case 6:
console.log("OptionsValidValue",OptionsValidValue);
console.log("questionAnswer",questionAnswer)
if (!OptionsValidValue.includes(questionAnswer)) {
return {
ok: false
}
}
break;
case 5: // chand entekhab
case 7:
if (Array.isArray(questionAnswer)) {
for (let ans of questionAnswer) {
if (!OptionsValidValue.includes(ans)) return { ok: false }
}
} else if (typeof questionAnswer === "string") {
for (let ans of questionAnswer.split(",")) {
if (!OptionsValidValue.includes(ans)) return { ok: false }
}
} else {
return { ok: false };
}
break;
case 8:
console.log("oomadinja");
console.log("javabesh", questionAnswer, isValidDateStrict(questionAnswer))
if (!isValidDateStrict(questionAnswer)) return { ok: false };
break;
case 10:
if (!isBoolean(questionAnswer)) return { ok: false }
break;
default:
return {
ok: false
}
}
return {
ok: true
}
}
const checkCondition = ({ data, condition, inputType = 2, options = null }, conditionArray = new Set()) => {
let ands = true;
for (const key in condition) {
const conditionValue = condition[key];
if (key == 'or') {
let ors = false;
for (const cond of conditionValue) {
const orConditionChecking = checkCondition({ data, condition: cond }, conditionArray);
ors = ors || orConditionChecking.ok;
conditionArray = new Set([...conditionArray, ...orConditionChecking.conditionArray])
if (ors) break;
}
ands = ands && ors;
} else {
if (data[key] == 'true') data[key] = true;
if (data[key] == 'false') data[key] = false;
switch (key) {
case [Op.gt]:
ands = ands && data[key] > conditionValue;
if (!conditionArray.has(key)) conditionArray.add(key);
break;
default:
ands = ands && data[key] == conditionValue;
if (!conditionArray.has(key)) conditionArray.add(key);
}
}
if (!ands) {
return { ok: false, conditionArray };
}
}
return { ok: true, conditionArray };
};
module.exports={
sleep,
convertStringToJson

Loading…
Cancel
Save