@pxp-nd/flow 1.1.17 → 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.
@@ -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, isCopy?: boolean): Promise<void>;
29
- copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean, isCopy?: boolean): Promise<{
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>;
@@ -66,6 +66,7 @@ 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"));
69
70
  const Node_2 = __importDefault(require("./Node"));
70
71
  const axios_1 = __importDefault(require("axios"));
71
72
  //import {configFacebookStrategy} from "./passport-facebook";
@@ -93,55 +94,22 @@ let Flow = class Flow extends core_1.Controller {
93
94
  }
94
95
  return restNodes;
95
96
  }
96
- async copyNodeConnections(nodeId, newNodeId, newFlowId, manager, isCopy = false) {
97
+ async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
97
98
  const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId, isActive: true }));
98
99
  for (let connection of connections) {
99
100
  const newNodeConnection = new NodeConnection_1.default();
100
101
  const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
101
102
  // get node from nodeIdChild
102
103
  const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
103
- const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager, false, isCopy);
104
+ const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
104
105
  Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
105
106
  const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
106
107
  }
107
108
  }
108
- async copyNode(node, newFlowId, manager, isFirst = false, isCopy = false) {
109
- var _a, _b, _c, _d;
109
+ async copyNode(node, newFlowId, manager, isFirst = false) {
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
- }
145
113
  Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
146
114
  const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
147
115
  if (isFirst) {
@@ -153,7 +121,7 @@ let Flow = class Flow extends core_1.Controller {
153
121
  await manager.save(duplicatedConnection);
154
122
  }
155
123
  // insert connection
156
- await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager, isCopy);
124
+ await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
157
125
  return { nodeId: insertNewNode.nodeId };
158
126
  }
159
127
  async createFlowFromFlow(params, manager) {
@@ -250,16 +218,15 @@ let Flow = class Flow extends core_1.Controller {
250
218
  status: 'off'
251
219
  };
252
220
  let flowDataClone;
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' });
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' });
257
224
  }
258
225
  else {
259
- flowDataClone = await (0, typeorm_1.getManager)().save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
226
+ flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
260
227
  }
261
228
  const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId, isInit: 'Y', isActive: true }, order: { nodeId: "ASC" } });
262
- dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true, isCopy);
229
+ dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true);
263
230
  return { success: true, flowId: flowDataClone.flowId };
264
231
  }
265
232
  else {
@@ -267,7 +234,7 @@ let Flow = class Flow extends core_1.Controller {
267
234
  }
268
235
  }
269
236
  async saveFlow(params, manager) {
270
- var _a, _b, _c, _d;
237
+ var _a, _b;
271
238
  let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
272
239
  let nodes = params.board.tasks ? params.board.tasks : [];
273
240
  let masterId = null;
@@ -322,7 +289,7 @@ let Flow = class Flow extends core_1.Controller {
322
289
  });
323
290
  if (connectionsToDel) {
324
291
  const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
325
- let flowNodeC = await manager.query(`DELETE
292
+ let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
326
293
  from twf_node_connection
327
294
  WHERE node_connection_id = ${originalNodeCIds}`);
328
295
  }
@@ -382,14 +349,7 @@ let Flow = class Flow extends core_1.Controller {
382
349
  }
383
350
  }
384
351
  catch (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
- }
352
+ console.error("Not valid json", error);
393
353
  }
394
354
  }
395
355
  }
@@ -437,7 +397,7 @@ let Flow = class Flow extends core_1.Controller {
437
397
  data: params,
438
398
  };
439
399
  const resControllerAxios = await (0, axios_1.default)(config);
440
- const chainedFlowId = (_d = resControllerAxios.data) === null || _d === void 0 ? void 0 : _d.flowId;
400
+ const chainedFlowId = (_b = resControllerAxios.data) === null || _b === void 0 ? void 0 : _b.flowId;
441
401
  const parsedValues = {
442
402
  flowId: chainedFlowId
443
403
  };
@@ -746,25 +706,21 @@ let Flow = class Flow extends core_1.Controller {
746
706
  validFlowInstances.push(flowInstance.flowInstanceId);
747
707
  }
748
708
  else {
749
- /*Commented because scheduled nodes shouldn't be affected by stopping
750
709
  let flowInstanceId = flowInstance.flowInstanceId;
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
- }*/
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
+ }
768
724
  }
769
725
  }
770
726
  if (validFlowInstances.length > 0) {
@@ -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;
@@ -24,7 +24,6 @@ export default class ActionType extends PxpEntity {
24
24
  controller: string;
25
25
  extraSchemaJson: string;
26
26
  actionsJson: string;
27
- onDuplicate: string;
28
27
  validationController: string;
29
28
  actions: Action[];
30
29
  }
@@ -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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",