@pxp-nd/flow 1.1.9 → 1.1.10
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.
|
@@ -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): Promise<void>;
|
|
29
|
-
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean): Promise<{
|
|
28
|
+
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager, isCopy?: boolean): Promise<void>;
|
|
29
|
+
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean, isCopy?: 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,22 +94,55 @@ 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, isCopy = false) {
|
|
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, isCopy);
|
|
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) {
|
|
109
|
+
async copyNode(node, newFlowId, manager, isFirst = false, isCopy = false) {
|
|
110
|
+
var _a, _b, _c, _d;
|
|
110
111
|
// insert new node
|
|
111
112
|
const newNode = new Node_1.default();
|
|
112
113
|
const { nodeId, flowId, createdAt, modifiedAt, ...nodeToCopy } = node;
|
|
114
|
+
if (((_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
|
+
}
|
|
113
146
|
Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
|
|
114
147
|
const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
|
|
115
148
|
if (isFirst) {
|
|
@@ -121,7 +154,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
121
154
|
await manager.save(duplicatedConnection);
|
|
122
155
|
}
|
|
123
156
|
// insert connection
|
|
124
|
-
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
|
|
157
|
+
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager, isCopy);
|
|
125
158
|
return { nodeId: insertNewNode.nodeId };
|
|
126
159
|
}
|
|
127
160
|
async createFlowFromFlow(params, manager) {
|
|
@@ -218,15 +251,17 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
218
251
|
status: 'off'
|
|
219
252
|
};
|
|
220
253
|
let flowDataClone;
|
|
254
|
+
let isCopy = false;
|
|
221
255
|
//if we have a vendoId as parameter the origin is a template
|
|
222
256
|
if (params.vendorId) {
|
|
223
257
|
flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
|
|
224
258
|
}
|
|
225
259
|
else {
|
|
226
260
|
flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
|
|
261
|
+
isCopy = true;
|
|
227
262
|
}
|
|
228
263
|
const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId, isInit: 'Y', isActive: true }, order: { nodeId: "ASC" } });
|
|
229
|
-
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true);
|
|
264
|
+
dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true, isCopy);
|
|
230
265
|
return { success: true, flowId: flowDataClone.flowId };
|
|
231
266
|
}
|
|
232
267
|
else {
|
|
@@ -719,7 +754,7 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
719
754
|
const queryBuilder = transactionalEntityManager.createQueryBuilder(NodeInstance_1.default, 'node_instance');
|
|
720
755
|
queryBuilder
|
|
721
756
|
.where('node_instance.flowInstanceId = :flowInstanceId', { flowInstanceId })
|
|
722
|
-
.andWhere('((node_instance.status IS NULL AND node_instance.schedule = :schedule) OR (node_instance.status = :status AND node_instance.schedule != :schedule))', {
|
|
757
|
+
.andWhere('((node_instance.status IS NULL AND (node_instance.schedule = :schedule OR node_instance.schedule IS NULL)) OR (node_instance.status = :status AND node_instance.schedule != :schedule AND node_instance.schedule IS NOT NULL))', {
|
|
723
758
|
status: 'executed',
|
|
724
759
|
schedule: '0000-00-00 00:00:00',
|
|
725
760
|
});
|