@pxp-nd/flow 1.1.16 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/Flow.d.ts +2 -2
- package/dist/controllers/Flow.js +14 -55
- package/dist/controllers/FlowInstance.d.ts +0 -1
- package/dist/controllers/FlowInstance.js +0 -21
- package/dist/controllers/NodeInstance.js +3 -0
- package/dist/entity/ActionType.d.ts +0 -1
- package/dist/entity/ActionType.js +0 -4
- package/package.json +1 -1
|
@@ -25,8 +25,8 @@ import { EntityManager } from 'typeorm';
|
|
|
25
25
|
import { Controller } from '@pxp-nd/core';
|
|
26
26
|
declare class Flow extends Controller {
|
|
27
27
|
get(params: Record<string, any>): Promise<unknown>;
|
|
28
|
-
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager
|
|
29
|
-
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean
|
|
28
|
+
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager): Promise<void>;
|
|
29
|
+
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean): Promise<{
|
|
30
30
|
nodeId: any;
|
|
31
31
|
}>;
|
|
32
32
|
createFlowFromFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -94,55 +94,22 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
94
94
|
}
|
|
95
95
|
return restNodes;
|
|
96
96
|
}
|
|
97
|
-
async copyNodeConnections(nodeId, newNodeId, newFlowId, manager
|
|
97
|
+
async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
|
|
98
98
|
const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId, isActive: true }));
|
|
99
99
|
for (let connection of connections) {
|
|
100
100
|
const newNodeConnection = new NodeConnection_1.default();
|
|
101
101
|
const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
|
|
102
102
|
// get node from nodeIdChild
|
|
103
103
|
const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
|
|
104
|
-
const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager
|
|
104
|
+
const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
|
|
105
105
|
Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
|
|
106
106
|
const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
async copyNode(node, newFlowId, manager, isFirst = false
|
|
110
|
-
var _a, _b, _c, _d;
|
|
109
|
+
async copyNode(node, newFlowId, manager, isFirst = false) {
|
|
111
110
|
// insert new node
|
|
112
111
|
const newNode = new Node_1.default();
|
|
113
112
|
const { nodeId, flowId, createdAt, modifiedAt, ...nodeToCopy } = node;
|
|
114
|
-
if (isCopy && ((_b = (_a = nodeToCopy === null || nodeToCopy === void 0 ? void 0 : nodeToCopy.action) === null || _a === void 0 ? void 0 : _a.actionType) === null || _b === void 0 ? void 0 : _b.onDuplicate) === 'duplicateChainedFlow') {
|
|
115
|
-
if ((_c = nodeToCopy === null || nodeToCopy === void 0 ? void 0 : nodeToCopy.action) === null || _c === void 0 ? void 0 : _c.configJsonTemplate) {
|
|
116
|
-
try {
|
|
117
|
-
const parsedConfig = JSON.parse(nodeToCopy.action.configJsonTemplate);
|
|
118
|
-
if (parsedConfig.addController && parsedConfig.template) {
|
|
119
|
-
const params = {
|
|
120
|
-
template: parsedConfig.template,
|
|
121
|
-
flowId: newFlowId,
|
|
122
|
-
};
|
|
123
|
-
const config = {
|
|
124
|
-
method: "post",
|
|
125
|
-
url: `http://localhost:${process.env.PORT}/api/${parsedConfig.addController}`,
|
|
126
|
-
headers: {
|
|
127
|
-
Authorization: "" + process.env.TOKEN_PXP_ND + "",
|
|
128
|
-
"Content-Type": "application/json",
|
|
129
|
-
},
|
|
130
|
-
data: params,
|
|
131
|
-
};
|
|
132
|
-
const resControllerAxios = await (0, axios_1.default)(config);
|
|
133
|
-
const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
|
|
134
|
-
const parsedValues = {
|
|
135
|
-
flowId: chainedFlowId
|
|
136
|
-
};
|
|
137
|
-
const newConfigJson = JSON.stringify(parsedValues);
|
|
138
|
-
nodeToCopy.actionConfigJson = newConfigJson;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
console.error("Not valid json", error);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
113
|
Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
|
|
147
114
|
const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
|
|
148
115
|
if (isFirst) {
|
|
@@ -154,7 +121,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
154
121
|
await manager.save(duplicatedConnection);
|
|
155
122
|
}
|
|
156
123
|
// insert connection
|
|
157
|
-
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager
|
|
124
|
+
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
|
|
158
125
|
return { nodeId: insertNewNode.nodeId };
|
|
159
126
|
}
|
|
160
127
|
async createFlowFromFlow(params, manager) {
|
|
@@ -251,16 +218,15 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
251
218
|
status: 'off'
|
|
252
219
|
};
|
|
253
220
|
let flowDataClone;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
|
|
221
|
+
//if we have a vendoId as parameter the origin is a template
|
|
222
|
+
if (params.vendorId) {
|
|
223
|
+
flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
|
|
258
224
|
}
|
|
259
225
|
else {
|
|
260
|
-
flowDataClone = await
|
|
226
|
+
flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
|
|
261
227
|
}
|
|
262
228
|
const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId, isInit: 'Y', isActive: true }, order: { nodeId: "ASC" } });
|
|
263
|
-
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true
|
|
229
|
+
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true);
|
|
264
230
|
return { success: true, flowId: flowDataClone.flowId };
|
|
265
231
|
}
|
|
266
232
|
else {
|
|
@@ -268,7 +234,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
268
234
|
}
|
|
269
235
|
}
|
|
270
236
|
async saveFlow(params, manager) {
|
|
271
|
-
var _a, _b
|
|
237
|
+
var _a, _b;
|
|
272
238
|
let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
|
|
273
239
|
let nodes = params.board.tasks ? params.board.tasks : [];
|
|
274
240
|
let masterId = null;
|
|
@@ -323,7 +289,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
323
289
|
});
|
|
324
290
|
if (connectionsToDel) {
|
|
325
291
|
const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
|
|
326
|
-
let flowNodeC = await
|
|
292
|
+
let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
|
|
327
293
|
from twf_node_connection
|
|
328
294
|
WHERE node_connection_id = ${originalNodeCIds}`);
|
|
329
295
|
}
|
|
@@ -383,14 +349,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
383
349
|
}
|
|
384
350
|
}
|
|
385
351
|
catch (error) {
|
|
386
|
-
|
|
387
|
-
const message = ((_c = (_b = error.response.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) || 'Unknown error';
|
|
388
|
-
throw new core_1.PxpError(400, message);
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
console.error("Not valid json", error);
|
|
392
|
-
throw new core_1.PxpError(500, 'Unexpected error while processing the request');
|
|
393
|
-
}
|
|
352
|
+
console.error("Not valid json", error);
|
|
394
353
|
}
|
|
395
354
|
}
|
|
396
355
|
}
|
|
@@ -438,7 +397,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
438
397
|
data: params,
|
|
439
398
|
};
|
|
440
399
|
const resControllerAxios = await (0, axios_1.default)(config);
|
|
441
|
-
const chainedFlowId = (
|
|
400
|
+
const chainedFlowId = (_b = resControllerAxios.data) === null || _b === void 0 ? void 0 : _b.flowId;
|
|
442
401
|
const parsedValues = {
|
|
443
402
|
flowId: chainedFlowId
|
|
444
403
|
};
|
|
@@ -753,7 +712,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
753
712
|
const queryBuilder = transactionalEntityManager.createQueryBuilder(NodeInstance_1.default, 'node_instance');
|
|
754
713
|
queryBuilder
|
|
755
714
|
.where('node_instance.flowInstanceId = :flowInstanceId', { flowInstanceId })
|
|
756
|
-
.andWhere('((node_instance.status IS NULL AND
|
|
715
|
+
.andWhere('((node_instance.status IS NULL AND node_instance.schedule = :schedule) OR (node_instance.status = :status AND node_instance.schedule != :schedule))', {
|
|
757
716
|
status: 'executed',
|
|
758
717
|
schedule: '0000-00-00 00:00:00',
|
|
759
718
|
});
|
|
@@ -18,6 +18,5 @@ declare class FlowInstance extends Controller {
|
|
|
18
18
|
processPending(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
19
19
|
eventProcesss(manager: EntityManager): Promise<void>;
|
|
20
20
|
checkConditions(viewData: Record<string, any>, flowId: number, actionId: number): Promise<boolean>;
|
|
21
|
-
insert(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
22
21
|
}
|
|
23
22
|
export default FlowInstance;
|
|
@@ -135,18 +135,6 @@ class FlowInstance extends core_1.Controller {
|
|
|
135
135
|
}
|
|
136
136
|
return res;
|
|
137
137
|
}
|
|
138
|
-
async insert(params, manager) {
|
|
139
|
-
const { flowId, dataId, status, actionId, originName = '', originKey = '' } = params;
|
|
140
|
-
let flowInstance = new FlowInstance_1.default();
|
|
141
|
-
flowInstance.flowId = flowId;
|
|
142
|
-
flowInstance.dataId = dataId;
|
|
143
|
-
flowInstance.originName = originName;
|
|
144
|
-
flowInstance.originKey = originKey;
|
|
145
|
-
flowInstance.actionId = actionId;
|
|
146
|
-
flowInstance.status = status;
|
|
147
|
-
flowInstance = await manager.save(FlowInstance_1.default, flowInstance);
|
|
148
|
-
return flowInstance;
|
|
149
|
-
}
|
|
150
138
|
}
|
|
151
139
|
__decorate([
|
|
152
140
|
(0, core_1.Post)(),
|
|
@@ -157,13 +145,4 @@ __decorate([
|
|
|
157
145
|
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
158
146
|
__metadata("design:returntype", Promise)
|
|
159
147
|
], FlowInstance.prototype, "processPending", null);
|
|
160
|
-
__decorate([
|
|
161
|
-
(0, core_1.Post)(),
|
|
162
|
-
(0, core_1.DbSettings)('Orm'),
|
|
163
|
-
(0, core_1.ReadOnly)(false),
|
|
164
|
-
(0, core_1.Log)(true),
|
|
165
|
-
__metadata("design:type", Function),
|
|
166
|
-
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
167
|
-
__metadata("design:returntype", Promise)
|
|
168
|
-
], FlowInstance.prototype, "insert", null);
|
|
169
148
|
exports.default = FlowInstance;
|
|
@@ -46,10 +46,12 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
46
46
|
lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
47
47
|
//todo after this we need to get the json variables and execute the view and conditions configured in the database
|
|
48
48
|
const { node, flowInstance, eventNode } = params;
|
|
49
|
+
console.log("RecursiveInstance flow-nd---> node:", node);
|
|
49
50
|
try {
|
|
50
51
|
const executeView = `select * from ${flowInstance.originName} where ${flowInstance.originKey} = ${flowInstance.dataId}`;
|
|
51
52
|
const resExecuteView = await (0, core_1.__)((0, typeorm_1.getManager)().query(executeView));
|
|
52
53
|
const resultFromOrigin = resExecuteView[0];
|
|
54
|
+
console.log("resultFromOrigin:", resultFromOrigin);
|
|
53
55
|
let mergeJson = {};
|
|
54
56
|
const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson }, }, } = node;
|
|
55
57
|
if (configJsonTemplate !== "" || actionConfigJson !== "") {
|
|
@@ -62,6 +64,7 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
62
64
|
...(actionConfigJsonObject || {}),
|
|
63
65
|
__resultFromOrigin: resultFromOrigin,
|
|
64
66
|
};
|
|
67
|
+
console.log("mergeJson::", mergeJson);
|
|
65
68
|
}
|
|
66
69
|
let nodeInstance = new NodeInstance_1.default();
|
|
67
70
|
nodeInstance.flowInstanceId = flowInstance.flowInstanceId;
|
|
@@ -73,10 +73,6 @@ __decorate([
|
|
|
73
73
|
(0, typeorm_1.Column)({ name: 'actions_json', type: 'text' }),
|
|
74
74
|
__metadata("design:type", String)
|
|
75
75
|
], ActionType.prototype, "actionsJson", void 0);
|
|
76
|
-
__decorate([
|
|
77
|
-
(0, typeorm_1.Column)({ name: 'on_duplicate', type: 'varchar' }),
|
|
78
|
-
__metadata("design:type", String)
|
|
79
|
-
], ActionType.prototype, "onDuplicate", void 0);
|
|
80
76
|
__decorate([
|
|
81
77
|
(0, typeorm_1.Column)({ name: 'validation_controller', type: 'text' }),
|
|
82
78
|
__metadata("design:type", String)
|