You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

106 lines
3.3 KiB

const path = require('path');
const fs = require('fs');
const { sleep } = require('./util');
const { getAllWorkflows } = require('./workflow');
const { getAllProcesses, getProcessPaths, getProcessPathsSubFlow } = require('./process');
require(path.join(process.cwd(), "..", "server", "dist", "database.js"));
(async function () {
await sleep(5e3);
console.time("WorkflowTester")
console.log("initilizing begin..");
const workflows = await getAllWorkflows({
id: {
[Op.gt]: 0
}
});
if (workflows.length == 0) throw "There is not any workflow";
const allWorkFlowInfo = {};
workflowsFor:
for await (const workflow of workflows) {
if (+workflow.id < 0) continue;
const processes = await getAllProcesses(workflow, {
subFlowId: null,
});
if (processes.length == 0) {
allWorkFlowInfo[workflow.id] = {
isValid: false,
root: {
valid: 0,
invalid: 0,
subFlowList: []
},
subFlow: {}
}
continue workflowsFor;
}
const { allPaths: tree, subFlowParentIds, invalidPathsWithoutEnding } = await getProcessPaths(processes, workflow);
allWorkFlowInfo[workflow.id] = {
isValid: invalidPathsWithoutEnding.length == 0 ? true : false,
root: {
// validPaths: tree,
// invalidPaths: invalidPathsWithoutEnding,
valid: tree.length,
invalid: invalidPathsWithoutEnding.length,
subFlowList: subFlowParentIds
},
subFlow: {}
}
const subFlowInfo = {}
subFlowFor:
for await (const subFlowId of subFlowParentIds) {
const processesSubFlow = await getAllProcesses(workflow, {
[Op.or]: [
{
subFlowId: subFlowId,
},
{
subFlowPid: subFlowId
}
]
})
if (processesSubFlow.length == 0) {
allWorkFlowInfo[workflow.id].isValid = false;
subFlowInfo[subFlowId] = {
valid: 0,
invalid: 0,
validSubTreePath: [],
invalidSubTreePath: [],
error: "این ورک فلو ساب آیدی ، هیچ زیرمجموعه ای ندارد"
}
continue subFlowFor;
}
const { subTreePath, invalidSubPathsWithoutEnding } = await getProcessPathsSubFlow(processesSubFlow, subFlowId, workflow);
subFlowInfo[subFlowId] = {
valid: subTreePath.length,
invalid: invalidSubPathsWithoutEnding.length,
// validSubTreePath: subTreePath,
// invalidSubTreePath: invalidSubPathsWithoutEnding
}
}
allWorkFlowInfo[workflow.id]["subFlow"] = subFlowInfo;
}
console.log("allWorkFlowInfo", JSON.stringify(allWorkFlowInfo, null, 2));
fs.writeFileSync("./result-pretty.json", JSON.stringify(allWorkFlowInfo, null, 2));
console.timeEnd("WorkflowTester")
console.log("DONE");
process.exit(0);
})()