@pxp-nd/flow 1.1.20 → 1.1.22

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>;
@@ -66,7 +66,6 @@ const Action_1 = __importDefault(require("../entity/Action"));
66
66
  const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
67
67
  const Flow_1 = __importDefault(require("../entity/Flow"));
68
68
  const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
69
- const NodeInstance_1 = __importDefault(require("../entity/NodeInstance"));
70
69
  const Node_2 = __importDefault(require("./Node"));
71
70
  const axios_1 = __importDefault(require("axios"));
72
71
  //import {configFacebookStrategy} from "./passport-facebook";
@@ -94,22 +93,55 @@ let Flow = class Flow extends core_1.Controller {
94
93
  }
95
94
  return restNodes;
96
95
  }
97
- async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
96
+ async copyNodeConnections(nodeId, newNodeId, newFlowId, manager, isCopy = false) {
98
97
  const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId, isActive: true }));
99
98
  for (let connection of connections) {
100
99
  const newNodeConnection = new NodeConnection_1.default();
101
100
  const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
102
101
  // get node from nodeIdChild
103
102
  const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
104
- const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
103
+ const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager, false, isCopy);
105
104
  Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
106
105
  const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
107
106
  }
108
107
  }
109
- async copyNode(node, newFlowId, manager, isFirst = false) {
108
+ async copyNode(node, newFlowId, manager, isFirst = false, isCopy = false) {
109
+ var _a, _b, _c, _d;
110
110
  // insert new node
111
111
  const newNode = new Node_1.default();
112
112
  const { nodeId, flowId, createdAt, modifiedAt, ...nodeToCopy } = node;
113
+ 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') {
114
+ if ((_c = nodeToCopy === null || nodeToCopy === void 0 ? void 0 : nodeToCopy.action) === null || _c === void 0 ? void 0 : _c.configJsonTemplate) {
115
+ try {
116
+ const parsedConfig = JSON.parse(nodeToCopy.action.configJsonTemplate);
117
+ if (parsedConfig.addController && parsedConfig.template) {
118
+ const params = {
119
+ template: parsedConfig.template,
120
+ flowId: newFlowId,
121
+ };
122
+ const config = {
123
+ method: "post",
124
+ url: `http://localhost:${process.env.PORT}/api/${parsedConfig.addController}`,
125
+ headers: {
126
+ Authorization: "" + process.env.TOKEN_PXP_ND + "",
127
+ "Content-Type": "application/json",
128
+ },
129
+ data: params,
130
+ };
131
+ const resControllerAxios = await (0, axios_1.default)(config);
132
+ const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
133
+ const parsedValues = {
134
+ flowId: chainedFlowId
135
+ };
136
+ const newConfigJson = JSON.stringify(parsedValues);
137
+ nodeToCopy.actionConfigJson = newConfigJson;
138
+ }
139
+ }
140
+ catch (error) {
141
+ console.error("Not valid json", error);
142
+ }
143
+ }
144
+ }
113
145
  Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
114
146
  const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
115
147
  if (isFirst) {
@@ -121,7 +153,7 @@ let Flow = class Flow extends core_1.Controller {
121
153
  await manager.save(duplicatedConnection);
122
154
  }
123
155
  // insert connection
124
- await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
156
+ await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager, isCopy);
125
157
  return { nodeId: insertNewNode.nodeId };
126
158
  }
127
159
  async createFlowFromFlow(params, manager) {
@@ -218,15 +250,16 @@ let Flow = class Flow extends core_1.Controller {
218
250
  status: 'off'
219
251
  };
220
252
  let flowDataClone;
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' });
253
+ let isCopy = false;
254
+ //if we have a name as parameter the origin is a template
255
+ if (params.name) {
256
+ flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
224
257
  }
225
258
  else {
226
- flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
259
+ flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
227
260
  }
228
261
  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);
262
+ dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true, isCopy);
230
263
  return { success: true, flowId: flowDataClone.flowId };
231
264
  }
232
265
  else {
@@ -234,7 +267,7 @@ let Flow = class Flow extends core_1.Controller {
234
267
  }
235
268
  }
236
269
  async saveFlow(params, manager) {
237
- var _a, _b;
270
+ var _a, _b, _c, _d;
238
271
  let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
239
272
  let nodes = params.board.tasks ? params.board.tasks : [];
240
273
  let masterId = null;
@@ -289,7 +322,7 @@ let Flow = class Flow extends core_1.Controller {
289
322
  });
290
323
  if (connectionsToDel) {
291
324
  const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
292
- let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
325
+ let flowNodeC = await manager.query(`DELETE
293
326
  from twf_node_connection
294
327
  WHERE node_connection_id = ${originalNodeCIds}`);
295
328
  }
@@ -349,7 +382,14 @@ let Flow = class Flow extends core_1.Controller {
349
382
  }
350
383
  }
351
384
  catch (error) {
352
- console.error("Not valid json", error);
385
+ if (axios_1.default.isAxiosError(error) && error.response) {
386
+ 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';
387
+ throw new core_1.PxpError(400, message);
388
+ }
389
+ else {
390
+ console.error("Not valid json", error);
391
+ throw new core_1.PxpError(500, 'Unexpected error while processing the request');
392
+ }
353
393
  }
354
394
  }
355
395
  }
@@ -397,7 +437,7 @@ let Flow = class Flow extends core_1.Controller {
397
437
  data: params,
398
438
  };
399
439
  const resControllerAxios = await (0, axios_1.default)(config);
400
- const chainedFlowId = (_b = resControllerAxios.data) === null || _b === void 0 ? void 0 : _b.flowId;
440
+ const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
401
441
  const parsedValues = {
402
442
  flowId: chainedFlowId
403
443
  };
@@ -706,21 +746,25 @@ let Flow = class Flow extends core_1.Controller {
706
746
  validFlowInstances.push(flowInstance.flowInstanceId);
707
747
  }
708
748
  else {
749
+ /*Commented because scheduled nodes shouldn't be affected by stopping
709
750
  let flowInstanceId = flowInstance.flowInstanceId;
710
- const totalNI = await NodeInstance_1.default.find({ flowInstanceId, isActive: true });
711
- const nodeInstances = await (0, typeorm_1.getManager)().transaction(async (transactionalEntityManager) => {
712
- const queryBuilder = transactionalEntityManager.createQueryBuilder(NodeInstance_1.default, 'node_instance');
713
- queryBuilder
714
- .where('node_instance.flowInstanceId = :flowInstanceId', { flowInstanceId })
715
- .andWhere('((node_instance.status IS NULL AND node_instance.schedule = :schedule) OR (node_instance.status = :status AND node_instance.schedule != :schedule))', {
716
- status: 'executed',
717
- schedule: '0000-00-00 00:00:00',
718
- });
719
- return queryBuilder.getMany();
720
- });
721
- if (totalNI.length > nodeInstances.length) {
722
- validFlowInstances.push(flowInstanceId);
723
- }
751
+ const totalNI = await NodeInstanceModel.find({ flowInstanceId, isActive: true});
752
+ const nodeInstances = await getManager().transaction(async (transactionalEntityManager) => {
753
+ const queryBuilder: SelectQueryBuilder<NodeInstanceModel> = transactionalEntityManager.createQueryBuilder(NodeInstanceModel, 'node_instance');
754
+ queryBuilder
755
+ .where('node_instance.flowInstanceId = :flowInstanceId', { flowInstanceId })
756
+ .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))', {
757
+ status: 'executed',
758
+ schedule: '0000-00-00 00:00:00',
759
+ });
760
+
761
+ return queryBuilder.getMany();
762
+ });
763
+
764
+
765
+ if (totalNI.length > nodeInstances.length ) {
766
+ validFlowInstances.push(flowInstanceId);
767
+ }*/
724
768
  }
725
769
  }
726
770
  if (validFlowInstances.length > 0) {
@@ -18,5 +18,6 @@ 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>;
21
22
  }
22
23
  export default FlowInstance;
@@ -135,6 +135,18 @@ 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
+ }
138
150
  }
139
151
  __decorate([
140
152
  (0, core_1.Post)(),
@@ -145,4 +157,13 @@ __decorate([
145
157
  __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
146
158
  __metadata("design:returntype", Promise)
147
159
  ], 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);
148
169
  exports.default = FlowInstance;
@@ -63,8 +63,10 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
63
63
  ...(configJsonTemplateObject || {}),
64
64
  ...(actionConfigJsonObject || {}),
65
65
  __resultFromOrigin: resultFromOrigin,
66
- flowInstance: flowInstance.flowInstanceId,
67
- nodeId: node.nodeId
66
+ uniqueArgs: {
67
+ flowInstance: flowInstance.flowInstanceId,
68
+ nodeId: node.nodeId
69
+ }
68
70
  };
69
71
  console.log("--->>>mergeJson::", mergeJson);
70
72
  }
@@ -24,6 +24,7 @@ export default class ActionType extends PxpEntity {
24
24
  controller: string;
25
25
  extraSchemaJson: string;
26
26
  actionsJson: string;
27
+ onDuplicate: string;
27
28
  validationController: string;
28
29
  actions: Action[];
29
30
  }
@@ -73,6 +73,10 @@ __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);
76
80
  __decorate([
77
81
  (0, typeorm_1.Column)({ name: 'validation_controller', type: 'text' }),
78
82
  __metadata("design:type", String)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.1.20",
3
+ "version": "1.1.22",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",