@pxp-nd/flow 1.0.50 → 1.0.51

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.
Files changed (113) hide show
  1. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/README.md +1 -0
  2. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Action.d.ts +20 -0
  3. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Action.js +82 -0
  4. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/ActionType.d.ts +17 -0
  5. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/ActionType.js +28 -0
  6. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Event.d.ts +17 -0
  7. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Event.js +28 -0
  8. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/FieldMap.d.ts +17 -0
  9. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/FieldMap.js +28 -0
  10. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Flow.d.ts +24 -0
  11. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Flow.js +116 -0
  12. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/FlowInstance.d.ts +20 -0
  13. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/FlowInstance.js +78 -0
  14. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Node.d.ts +23 -0
  15. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/Node.js +273 -0
  16. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/NodeInstance.d.ts +21 -0
  17. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/NodeInstance.js +165 -0
  18. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/OriginName.d.ts +17 -0
  19. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/OriginName.js +28 -0
  20. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/index.d.ts +11 -0
  21. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/controllers/index.js +25 -0
  22. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Action.d.ts +20 -0
  23. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Action.js +85 -0
  24. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/ActionType.d.ts +16 -0
  25. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/ActionType.js +71 -0
  26. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Event.d.ts +9 -0
  27. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Event.js +44 -0
  28. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/FieldMap.d.ts +11 -0
  29. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/FieldMap.js +52 -0
  30. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Flow.d.ts +14 -0
  31. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Flow.js +60 -0
  32. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/FlowInstance.d.ts +16 -0
  33. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/FlowInstance.js +69 -0
  34. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Node.d.ts +23 -0
  35. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/Node.js +93 -0
  36. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/NodeConnection.d.ts +10 -0
  37. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/NodeConnection.js +49 -0
  38. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/NodeInstance.d.ts +13 -0
  39. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/NodeInstance.js +58 -0
  40. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/OriginName.d.ts +9 -0
  41. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/OriginName.js +43 -0
  42. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/index.d.ts +23 -0
  43. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/entity/index.js +27 -0
  44. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/index.d.ts +3 -0
  45. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/index.js +15 -0
  46. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/subscribers/Event.d.ts +21 -0
  47. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/subscribers/Event.js +83 -0
  48. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/subscribers/index.d.ts +3 -0
  49. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/dist/subscribers/index.js +6 -0
  50. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/package.json +39 -0
  51. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/tsconfig.json +29 -0
  52. package/.yalc/@pxp-nd/flow/.yalc/@pxp-nd/flow/yalc.sig +1 -0
  53. package/.yalc/@pxp-nd/flow/README.md +1 -0
  54. package/.yalc/@pxp-nd/flow/dist/controllers/Action.d.ts +20 -0
  55. package/.yalc/@pxp-nd/flow/dist/controllers/Action.js +82 -0
  56. package/.yalc/@pxp-nd/flow/dist/controllers/ActionType.d.ts +17 -0
  57. package/.yalc/@pxp-nd/flow/dist/controllers/ActionType.js +28 -0
  58. package/.yalc/@pxp-nd/flow/dist/controllers/Event.d.ts +17 -0
  59. package/.yalc/@pxp-nd/flow/dist/controllers/Event.js +28 -0
  60. package/.yalc/@pxp-nd/flow/dist/controllers/FieldMap.d.ts +17 -0
  61. package/.yalc/@pxp-nd/flow/dist/controllers/FieldMap.js +28 -0
  62. package/.yalc/@pxp-nd/flow/dist/controllers/Flow.d.ts +33 -0
  63. package/.yalc/@pxp-nd/flow/dist/controllers/Flow.js +469 -0
  64. package/.yalc/@pxp-nd/flow/dist/controllers/FlowInstance.d.ts +20 -0
  65. package/.yalc/@pxp-nd/flow/dist/controllers/FlowInstance.js +84 -0
  66. package/.yalc/@pxp-nd/flow/dist/controllers/Node.d.ts +23 -0
  67. package/.yalc/@pxp-nd/flow/dist/controllers/Node.js +273 -0
  68. package/.yalc/@pxp-nd/flow/dist/controllers/NodeInstance.d.ts +21 -0
  69. package/.yalc/@pxp-nd/flow/dist/controllers/NodeInstance.js +191 -0
  70. package/.yalc/@pxp-nd/flow/dist/controllers/OriginName.d.ts +17 -0
  71. package/.yalc/@pxp-nd/flow/dist/controllers/OriginName.js +28 -0
  72. package/.yalc/@pxp-nd/flow/dist/controllers/index.d.ts +11 -0
  73. package/.yalc/@pxp-nd/flow/dist/controllers/index.js +25 -0
  74. package/.yalc/@pxp-nd/flow/dist/entity/Action.d.ts +20 -0
  75. package/.yalc/@pxp-nd/flow/dist/entity/Action.js +85 -0
  76. package/.yalc/@pxp-nd/flow/dist/entity/ActionType.d.ts +16 -0
  77. package/.yalc/@pxp-nd/flow/dist/entity/ActionType.js +71 -0
  78. package/.yalc/@pxp-nd/flow/dist/entity/Event.d.ts +9 -0
  79. package/.yalc/@pxp-nd/flow/dist/entity/Event.js +44 -0
  80. package/.yalc/@pxp-nd/flow/dist/entity/FieldMap.d.ts +11 -0
  81. package/.yalc/@pxp-nd/flow/dist/entity/FieldMap.js +52 -0
  82. package/.yalc/@pxp-nd/flow/dist/entity/Flow.d.ts +14 -0
  83. package/.yalc/@pxp-nd/flow/dist/entity/Flow.js +60 -0
  84. package/.yalc/@pxp-nd/flow/dist/entity/FlowInstance.d.ts +16 -0
  85. package/.yalc/@pxp-nd/flow/dist/entity/FlowInstance.js +69 -0
  86. package/.yalc/@pxp-nd/flow/dist/entity/Node.d.ts +23 -0
  87. package/.yalc/@pxp-nd/flow/dist/entity/Node.js +93 -0
  88. package/.yalc/@pxp-nd/flow/dist/entity/NodeConnection.d.ts +10 -0
  89. package/.yalc/@pxp-nd/flow/dist/entity/NodeConnection.js +49 -0
  90. package/.yalc/@pxp-nd/flow/dist/entity/NodeInstance.d.ts +13 -0
  91. package/.yalc/@pxp-nd/flow/dist/entity/NodeInstance.js +58 -0
  92. package/.yalc/@pxp-nd/flow/dist/entity/OriginName.d.ts +9 -0
  93. package/.yalc/@pxp-nd/flow/dist/entity/OriginName.js +43 -0
  94. package/.yalc/@pxp-nd/flow/dist/entity/index.d.ts +23 -0
  95. package/.yalc/@pxp-nd/flow/dist/entity/index.js +27 -0
  96. package/.yalc/@pxp-nd/flow/dist/index.d.ts +3 -0
  97. package/.yalc/@pxp-nd/flow/dist/index.js +19 -0
  98. package/.yalc/@pxp-nd/flow/dist/subscribers/Event.d.ts +21 -0
  99. package/.yalc/@pxp-nd/flow/dist/subscribers/Event.js +84 -0
  100. package/.yalc/@pxp-nd/flow/dist/subscribers/index.d.ts +3 -0
  101. package/.yalc/@pxp-nd/flow/dist/subscribers/index.js +6 -0
  102. package/.yalc/@pxp-nd/flow/package.json +39 -0
  103. package/.yalc/@pxp-nd/flow/tsconfig.json +29 -0
  104. package/.yalc/@pxp-nd/flow/yalc.lock +9 -0
  105. package/.yalc/@pxp-nd/flow/yalc.sig +1 -0
  106. package/dist/controllers/Flow.d.ts +1 -1
  107. package/dist/controllers/Flow.js +3 -1
  108. package/dist/entity/Action.d.ts +1 -0
  109. package/dist/entity/Action.js +4 -0
  110. package/dist/entity/Flow.d.ts +1 -0
  111. package/dist/entity/Flow.js +4 -0
  112. package/package.json +1 -1
  113. package/yalc.lock +9 -0
@@ -0,0 +1,469 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright(c) 2021 Qorus Inc
4
+ * * All rights reserved
5
+ * * ******************************************************************************
6
+ * * NAME: Flow.ts
7
+ * * DEVELOPER: Jaime Figueroa
8
+ * * DESCRIPTION: Flow Controller
9
+ * * REVISIONS:
10
+ * * Date Change ID Author Description
11
+ * * -------------- ----------- -------------- ------------------------------------
12
+ * 08-Jul-2021 Jaime Rivera Created
13
+ * 18-Jul-2023 SP28JUL23 Mercedes Zambrana Add deleteFlow, saveFlowName, duplicateFlow
14
+ * 02-Aug-2023 SP11AUG23 Mercedes Zambrana Add validations in deleteFlow and saveFlow
15
+ * 15-Aug-2023 SP25AUG23 Rensi Arteaga Add logic to duplicate flows templates
16
+ * ******************************************************************************
17
+ */
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __metadata = (this && this.__metadata) || function (k, v) {
25
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ const typeorm_1 = require("typeorm");
32
+ const core_1 = require("@pxp-nd/core");
33
+ const Node_1 = __importDefault(require("../entity/Node"));
34
+ const Action_1 = __importDefault(require("../entity/Action"));
35
+ const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
36
+ const Flow_1 = __importDefault(require("../entity/Flow"));
37
+ let Flow = class Flow extends core_1.Controller {
38
+ async get(params) {
39
+ const nodes = await Node_1.default.find({ flowId: params.flowId });
40
+ const restNodes = [];
41
+ for (let node of nodes) {
42
+ const { actionConfigJson, action: { actionType: { schemaJson } } } = node;
43
+ const actionConfigJsonObject = actionConfigJson ? JSON.parse(actionConfigJson) : {};
44
+ const schemaJsonObject = schemaJson ? JSON.parse(schemaJson) : {};
45
+ const valuesForShowingInNode = {};
46
+ Object.entries(schemaJsonObject).filter(([n, sjo]) => sjo.showInNode === true).forEach(([nameKey, json]) => {
47
+ valuesForShowingInNode[nameKey] = {
48
+ label: json.label,
49
+ value: actionConfigJsonObject[nameKey] || null
50
+ };
51
+ });
52
+ const nodeRow = {
53
+ ...node,
54
+ valuesForShowingInNode
55
+ };
56
+ const connections = await NodeConnection_1.default.find({ nodeIdMaster: node.nodeId });
57
+ restNodes.push({ node: nodeRow, connections: connections.map(c => c.nodeIdChild) });
58
+ }
59
+ return restNodes;
60
+ }
61
+ async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
62
+ const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId }));
63
+ for (let connection of connections) {
64
+ const newNodeConnection = new NodeConnection_1.default();
65
+ const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
66
+ // get node from nodeIdChild
67
+ const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
68
+ const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
69
+ Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
70
+ const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
71
+ }
72
+ }
73
+ async copyNode(node, newFlowId, manager) {
74
+ // insert new node
75
+ const newNode = new Node_1.default();
76
+ const { nodeId, flowId, createdAt, modifiedAt, actionConfigJson, ...nodeToCopy } = node;
77
+ Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
78
+ const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
79
+ // insert connection
80
+ await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
81
+ return { nodeId: insertNewNode.nodeId };
82
+ }
83
+ async createFlowFromFlow(params, manager) {
84
+ // we need clone the flow selected
85
+ const dataFlow = await (0, core_1.__)(Flow_1.default.findOne(params.flowId));
86
+ const { flowId, createdAt, modifiedAt, nodes, ...flowToCopy } = dataFlow;
87
+ const newFlow = new Flow_1.default();
88
+ Object.assign(newFlow, flowToCopy);
89
+ newFlow.name = params.name;
90
+ newFlow.description = params.description;
91
+ const insertNewFlow = await (0, core_1.__)(manager.save(Flow_1.default, newFlow));
92
+ // create the nodes
93
+ // get the first node "the trigger node"
94
+ const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId }, order: { nodeId: "ASC" } });
95
+ dataNode && await this.copyNode(dataNode, insertNewFlow.flowId, manager);
96
+ return { flowId: insertNewFlow.flowId };
97
+ }
98
+ async deleteFlow(params, manager) {
99
+ let dataFlow = await (0, core_1.__)(Flow_1.default.findOne(params.flowId));
100
+ if (dataFlow) {
101
+ dataFlow.isActive = 0;
102
+ dataFlow.enabled = 'N';
103
+ const updFlow = await (0, core_1.__)(manager.save(dataFlow));
104
+ if (updFlow) {
105
+ let flowInstance = `UPDATE twf_flow_instance SET
106
+ is_active = 'N' WHERE flow_id = ${updFlow.flowId}`;
107
+ await manager.query(flowInstance);
108
+ const nodesToInact = await manager.find(Node_1.default, { flowId: updFlow.flowId, isActive: true });
109
+ if (nodesToInact.length > 0) {
110
+ let flowNode = `UPDATE twf_node SET
111
+ is_active = 'N' WHERE flow_id = ${updFlow.flowId}`;
112
+ await manager.query(flowNode);
113
+ const nodesToInact = await manager.find(Node_1.default, { flowId: updFlow.flowId });
114
+ const originalNodeIds = nodesToInact.map((node) => node.nodeId);
115
+ const connectionsToInact = await manager.find(NodeConnection_1.default, {
116
+ where: { nodeIdChild: (0, typeorm_1.In)(originalNodeIds) } // Suponiendo que originalNodeIds contiene los IDs de los nodos originales que deseas duplicar
117
+ });
118
+ const originalNodeCIds = connectionsToInact.map((node) => node.nodeConnectionId);
119
+ if (originalNodeCIds.length > 0) {
120
+ let flowNodeC = `UPDATE twf_node_connection SET
121
+ is_active = 'N' WHERE node_connection_id in ( ${originalNodeCIds})`;
122
+ await manager.query(flowNodeC);
123
+ }
124
+ }
125
+ return { success: true };
126
+ }
127
+ else {
128
+ return { success: false };
129
+ }
130
+ }
131
+ else {
132
+ return { success: false };
133
+ }
134
+ }
135
+ async saveFlowName(params, manager) {
136
+ let dataFlow = await (0, core_1.__)(Flow_1.default.findOne(params.flowId));
137
+ if (dataFlow) {
138
+ dataFlow.name = params.name;
139
+ const updFlow = await (0, core_1.__)(manager.save(dataFlow));
140
+ return { success: true };
141
+ }
142
+ else {
143
+ return { success: false };
144
+ }
145
+ }
146
+ async duplicateFlow(params, manager) {
147
+ const flowData = await manager.findOne(Flow_1.default, params.flowId);
148
+ if (flowData) {
149
+ const flowToClone = {
150
+ ...flowData,
151
+ flowId: undefined,
152
+ nodes: [],
153
+ createdAt: undefined
154
+ };
155
+ let flowDataClone;
156
+ //if we have a vendoId as parameter the origin is a template
157
+ if (params.vendorId) {
158
+ flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
159
+ }
160
+ else {
161
+ flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
162
+ }
163
+ const nodesToDuplicate = await manager.find(Node_1.default, { flowId: flowData === null || flowData === void 0 ? void 0 : flowData.flowId, isActive: true });
164
+ if (nodesToDuplicate) {
165
+ const originalNodeIds = nodesToDuplicate.map((node) => node.nodeId);
166
+ const duplicatedNodes = nodesToDuplicate.map((node) => {
167
+ const duplicatedNode = manager.create(Node_1.default, { ...node, nodeId: undefined });
168
+ duplicatedNode.flowId = flowDataClone.flowId;
169
+ return duplicatedNode;
170
+ });
171
+ const savedNodes = await manager.save(duplicatedNodes);
172
+ const newNodeIds = savedNodes.map((node) => node.nodeId);
173
+ const connectionsToDuplicate = await manager.find(NodeConnection_1.default, {
174
+ where: { nodeIdChild: (0, typeorm_1.In)(originalNodeIds) }
175
+ });
176
+ const duplicatedConnections = newNodeIds.map((nodeId, index) => {
177
+ const duplicatedConnection = manager.create(NodeConnection_1.default, {
178
+ nodeConnectionId: undefined,
179
+ nodeIdMaster: index === 0 ? null : newNodeIds[index - 1],
180
+ nodeIdChild: nodeId,
181
+ });
182
+ return duplicatedConnection;
183
+ });
184
+ await manager.save(duplicatedConnections);
185
+ }
186
+ return { success: true, flowId: flowDataClone.flowId };
187
+ }
188
+ else {
189
+ return { success: false, "respuesta": "No Flow" };
190
+ }
191
+ }
192
+ async saveFlow(params, manager) {
193
+ let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
194
+ let nodes = params.board.tasks ? params.board.tasks : [];
195
+ let masterId = null;
196
+ let id = null;
197
+ let newId = null;
198
+ let flowId = null;
199
+ let taskIds = [];
200
+ if (nodeRefIds.length === 0) {
201
+ let nodeDelIdd = parseInt(params.board.deleteId.split("-")[1]);
202
+ const lastNoded = await Node_1.default.findOne({
203
+ where: {
204
+ nodeId: nodeDelIdd
205
+ }
206
+ });
207
+ flowId = lastNoded.flowId;
208
+ }
209
+ else {
210
+ flowId = params.board.flowId;
211
+ for (const nodeId of nodeRefIds) {
212
+ if (nodeId != 'new') {
213
+ id = parseInt(nodeId.split("node-")[1]);
214
+ if (!id) {
215
+ const lastNode = await Node_1.default.findOne({
216
+ where: {
217
+ flowId: flowId,
218
+ },
219
+ order: {
220
+ nodeId: 'DESC', // Ordena por ID en orden descendente para obtener el último registro
221
+ },
222
+ });
223
+ id = lastNode.nodeId;
224
+ }
225
+ taskIds.push(id);
226
+ const connectionsToDel = await manager.find(NodeConnection_1.default, {
227
+ where: { nodeIdChild: id }
228
+ });
229
+ if (connectionsToDel) {
230
+ const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
231
+ let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
232
+ from twf_node_connection
233
+ WHERE node_connection_id = ${originalNodeCIds}`);
234
+ }
235
+ }
236
+ else {
237
+ taskIds.push('new');
238
+ }
239
+ //}
240
+ }
241
+ }
242
+ if (params.board.origin == 'deleteTask') {
243
+ let nodeDelId = parseInt(params.board.deleteId.split("-")[1]);
244
+ if (nodeDelId) {
245
+ //If there are some nodes in node_connections after delete all records sent, to inactive node
246
+ let connectNoDel = await (0, typeorm_1.getManager)().query(`SELECT n.node_id
247
+ from twf_node_connection nd
248
+ inner join twf_node n on n.node_id = nd.node_id_child
249
+ WHERE n.node_id = ${nodeDelId}`);
250
+ const currentNodesIds = connectNoDel.map((record) => record.node_id);
251
+ // Get nodes to remove
252
+ const nodesToRemove = currentNodesIds.filter((nodeId) => !taskIds.includes(nodeId.toString()));
253
+ // Inactive nodes
254
+ if (nodesToRemove.length > 0) {
255
+ const delNodeConnect = await manager.delete(NodeConnection_1.default, { nodeIdChild: nodesToRemove[0] });
256
+ if (delNodeConnect) {
257
+ let dNode = `UPDATE twf_node
258
+ SET is_active = 'N'
259
+ WHERE node_id = ${nodesToRemove[0]}`;
260
+ await manager.query(dNode);
261
+ }
262
+ }
263
+ }
264
+ }
265
+ if (nodeRefIds.length === 0) {
266
+ }
267
+ else {
268
+ for (const nodeId of taskIds) {
269
+ if (nodeId === 'new') {
270
+ //get information about Action
271
+ const newAction = await Action_1.default.findOne({ code: nodes[`${nodeId}`].action.code });
272
+ const newNode = manager.create(Node_1.default, {
273
+ nodeId: undefined,
274
+ flowId: nodes[`${nodeId}`].flowId,
275
+ isInit: 'N',
276
+ actionId: newAction.actionId
277
+ });
278
+ const saveNode = await manager.save(newNode);
279
+ id = saveNode.nodeId;
280
+ newId = saveNode.nodeId;
281
+ }
282
+ else {
283
+ id = nodeId;
284
+ }
285
+ //save in node and node_connection
286
+ const newConnection = manager.create(NodeConnection_1.default, {
287
+ nodeConnectionId: undefined,
288
+ nodeIdMaster: masterId,
289
+ nodeIdChild: id,
290
+ });
291
+ masterId = id;
292
+ const savedNodes = await manager.save(newConnection);
293
+ // }
294
+ }
295
+ //}
296
+ }
297
+ return { success: true, nodeId: newId };
298
+ }
299
+ async getFlowRender(params) {
300
+ let actions = await (0, typeorm_1.getManager)()
301
+ .createQueryBuilder(Action_1.default, "a")
302
+ .select([
303
+ "a.actionId",
304
+ "a.code",
305
+ "a.name",
306
+ "a.description",
307
+ "at.name"
308
+ ])
309
+ .innerJoin("a.actionType", "at")
310
+ .where(`a.isActive = 1 and a.hidden = 'N'`)
311
+ .getMany();
312
+ const connections = await (0, typeorm_1.getManager)()
313
+ .createQueryBuilder(NodeConnection_1.default, "nc")
314
+ .select([
315
+ "nc.nodeIdMaster",
316
+ "nc.nodeIdChild",
317
+ ])
318
+ .innerJoin("nc.childNode", "cn")
319
+ .where(`cn.isActive = 1 and cn.flowId = :flowId`, { flowId: params.flowId })
320
+ .getMany();
321
+ const nodes = await (0, typeorm_1.getManager)()
322
+ .createQueryBuilder(Node_1.default, "n")
323
+ .select([
324
+ "n.nodeId",
325
+ "n.flowId",
326
+ "a.code",
327
+ "a.name",
328
+ "a.description",
329
+ ])
330
+ .innerJoin("n.action", "a")
331
+ .where(`n.isActive = 1 and n.flowId = :flowId`, { flowId: params.flowId })
332
+ .getMany();
333
+ let sortedNodes = this.sortNodesByConnections(nodes, connections);
334
+ actions.forEach((item) => {
335
+ item.actionId = `action-${item.actionId}`;
336
+ });
337
+ sortedNodes.forEach((item) => {
338
+ item.node = { nodeId: item.nodeId };
339
+ item.nodeId = `node-${item.nodeId}`;
340
+ });
341
+ const actionIds = actions.map((item) => item.actionId);
342
+ const nodeIds = sortedNodes.map((item) => item.nodeId);
343
+ sortedNodes = sortedNodes.map(({ nodeId, ...rest }) => {
344
+ return { id: nodeId, ...rest };
345
+ });
346
+ const modActions = actions.map(({ actionId, ...rest }) => {
347
+ return { id: actionId, type: 'template', ...rest };
348
+ });
349
+ const tasks = [...modActions, ...sortedNodes];
350
+ const tasksObject = tasks.reduce((acc, obj) => {
351
+ acc[obj.id] = obj;
352
+ return acc;
353
+ }, {});
354
+ let response = {
355
+ board: {
356
+ columns: {
357
+ "1-column-config-nodes": {
358
+ id: "1-column-config-nodes",
359
+ name: "Add Nodes",
360
+ taskIds: actionIds,
361
+ },
362
+ "2-column-nodes-configured": {
363
+ id: "2-column-nodes-configured",
364
+ name: "Test Flow",
365
+ taskIds: nodeIds,
366
+ }
367
+ },
368
+ tasks: tasksObject,
369
+ ordered: [
370
+ "1-column-config-nodes",
371
+ "2-column-nodes-configured"
372
+ ],
373
+ }
374
+ };
375
+ return response;
376
+ }
377
+ sortNodesByConnections(nodes, connections) {
378
+ const nodeMap = new Map();
379
+ nodes.forEach((node) => nodeMap.set(node.nodeId, node));
380
+ const sortedNodes = [];
381
+ const visitedNodes = new Set();
382
+ function dfs(nodeId) {
383
+ visitedNodes.add(nodeId);
384
+ const node = nodeMap.get(nodeId);
385
+ if (node) {
386
+ sortedNodes.push(node);
387
+ }
388
+ const connectedNodes = connections.filter((connection) => connection.nodeIdMaster === nodeId);
389
+ connectedNodes.forEach((connection) => {
390
+ if (!visitedNodes.has(connection.nodeIdChild)) {
391
+ dfs(connection.nodeIdChild);
392
+ }
393
+ });
394
+ }
395
+ connections.forEach((connection) => {
396
+ if (connection.nodeIdMaster === null && !visitedNodes.has(connection.nodeIdChild)) {
397
+ dfs(connection.nodeIdChild);
398
+ }
399
+ });
400
+ return sortedNodes;
401
+ }
402
+ };
403
+ __decorate([
404
+ (0, core_1.Get)(),
405
+ (0, core_1.DbSettings)('Orm'),
406
+ (0, core_1.ReadOnly)(true),
407
+ (0, core_1.Log)(true),
408
+ __metadata("design:type", Function),
409
+ __metadata("design:paramtypes", [Object]),
410
+ __metadata("design:returntype", Promise)
411
+ ], Flow.prototype, "get", null);
412
+ __decorate([
413
+ (0, core_1.Post)(),
414
+ (0, core_1.DbSettings)('Orm'),
415
+ (0, core_1.ReadOnly)(false),
416
+ (0, core_1.Log)(true),
417
+ __metadata("design:type", Function),
418
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
419
+ __metadata("design:returntype", Promise)
420
+ ], Flow.prototype, "createFlowFromFlow", null);
421
+ __decorate([
422
+ (0, core_1.Post)(),
423
+ (0, core_1.DbSettings)('Orm'),
424
+ (0, core_1.ReadOnly)(false),
425
+ (0, core_1.Log)(true),
426
+ __metadata("design:type", Function),
427
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
428
+ __metadata("design:returntype", Promise)
429
+ ], Flow.prototype, "deleteFlow", null);
430
+ __decorate([
431
+ (0, core_1.Post)(),
432
+ (0, core_1.DbSettings)('Orm'),
433
+ (0, core_1.ReadOnly)(false),
434
+ (0, core_1.Log)(true),
435
+ __metadata("design:type", Function),
436
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
437
+ __metadata("design:returntype", Promise)
438
+ ], Flow.prototype, "saveFlowName", null);
439
+ __decorate([
440
+ (0, core_1.Post)(),
441
+ (0, core_1.DbSettings)('Orm'),
442
+ (0, core_1.ReadOnly)(false),
443
+ (0, core_1.Log)(true),
444
+ __metadata("design:type", Function),
445
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
446
+ __metadata("design:returntype", Promise)
447
+ ], Flow.prototype, "duplicateFlow", null);
448
+ __decorate([
449
+ (0, core_1.Post)(),
450
+ (0, core_1.DbSettings)('Orm'),
451
+ (0, core_1.ReadOnly)(false),
452
+ (0, core_1.Log)(true),
453
+ __metadata("design:type", Function),
454
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
455
+ __metadata("design:returntype", Promise)
456
+ ], Flow.prototype, "saveFlow", null);
457
+ __decorate([
458
+ (0, core_1.Get)(),
459
+ (0, core_1.DbSettings)('Orm'),
460
+ (0, core_1.ReadOnly)(true),
461
+ (0, core_1.Log)(true),
462
+ __metadata("design:type", Function),
463
+ __metadata("design:paramtypes", [Object]),
464
+ __metadata("design:returntype", Promise)
465
+ ], Flow.prototype, "getFlowRender", null);
466
+ Flow = __decorate([
467
+ (0, core_1.Model)('flow-nd/Flow')
468
+ ], Flow);
469
+ exports.default = Flow;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Kplian 2021
3
+ *
4
+ * MIT
5
+ *
6
+ * NodeInstance Controller
7
+ *
8
+ * @summary Member Controller
9
+ * @author Favio Figueroa
10
+ * Jaime Rivera
11
+ *
12
+ * Created at : 2021-07-08 12:55:38
13
+ * Last modified :
14
+ */
15
+ import { EntityManager } from 'typeorm';
16
+ import { Controller } from '@pxp-nd/core';
17
+ declare class FlowInstance extends Controller {
18
+ processPending(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
19
+ }
20
+ export default FlowInstance;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Kplian 2021
4
+ *
5
+ * MIT
6
+ *
7
+ * NodeInstance Controller
8
+ *
9
+ * @summary Member Controller
10
+ * @author Favio Figueroa
11
+ * Jaime Rivera
12
+ *
13
+ * Created at : 2021-07-08 12:55:38
14
+ * Last modified :
15
+ */
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const typeorm_1 = require("typeorm");
30
+ const core_1 = require("@pxp-nd/core");
31
+ const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
32
+ const common_1 = require("@pxp-nd/common");
33
+ const NodeInstance_1 = __importDefault(require("./NodeInstance"));
34
+ const NodeInstance_2 = __importDefault(require("../entity/NodeInstance"));
35
+ const Node_1 = __importDefault(require("../entity/Node"));
36
+ class FlowInstance extends core_1.Controller {
37
+ async processPending(params, manager) {
38
+ const flag = await common_1.GlobalData.findOne({ data: 'wf_processing_pending_flows_flag' });
39
+ if (flag) {
40
+ if (flag.value == 'true') {
41
+ throw new core_1.PxpError(400, 'Already processing pending flows');
42
+ }
43
+ flag.value = 'true';
44
+ let flowInstanceIdProcessing = -1;
45
+ await (0, typeorm_1.getManager)().save(flag);
46
+ try {
47
+ const maxFlows = await common_1.GlobalData.findOne({ data: 'wf_max_concurrent_flows_process' });
48
+ const flowInstances = await FlowInstance_1.default.find({ take: (maxFlows && maxFlows.value), where: [{ status: 'pending' }], order: { flowInstanceId: "ASC" } });
49
+ for (const flowInstance of flowInstances) {
50
+ flowInstanceIdProcessing = flowInstance.flowInstanceId;
51
+ const node = await Node_1.default.findOne({ where: { actionId: flowInstance.actionId, flowId: flowInstance.flowId } });
52
+ const CNodeInstance = new NodeInstance_1.default('flow-nd', NodeInstance_2.default);
53
+ try {
54
+ await CNodeInstance.RecursiveInstance({ node, flowInstance });
55
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'processed' });
56
+ }
57
+ catch (error) {
58
+ console.log(error);
59
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'error' });
60
+ }
61
+ await manager.update(FlowInstance_1.default, { flowInstanceId: flowInstance.flowInstanceId }, { status: 'processed' });
62
+ }
63
+ }
64
+ catch (error) {
65
+ flag.value = 'false';
66
+ await (0, typeorm_1.getManager)().save(flag);
67
+ throw new core_1.PxpError(400, 'Error processing flow: ' + flowInstanceIdProcessing);
68
+ }
69
+ flag.value = 'false';
70
+ await (0, typeorm_1.getManager)().save(flag);
71
+ }
72
+ return { success: true };
73
+ }
74
+ }
75
+ __decorate([
76
+ (0, core_1.Post)(),
77
+ (0, core_1.DbSettings)('Orm'),
78
+ (0, core_1.ReadOnly)(false),
79
+ (0, core_1.Log)(true),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
82
+ __metadata("design:returntype", Promise)
83
+ ], FlowInstance.prototype, "processPending", null);
84
+ exports.default = FlowInstance;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Effex 2021
3
+ *
4
+ * MIT
5
+ *
6
+ * Member Controller
7
+ *
8
+ * @summary Member Controller
9
+ * @author Favio Figueroa
10
+ *
11
+ * Created at : 2021-07-08 12:55:38
12
+ * Last modified :
13
+ */
14
+ import { EntityManager } from 'typeorm';
15
+ import { Controller } from '@pxp-nd/core';
16
+ declare class Node extends Controller {
17
+ getNodeData(node: any, dataId: any, manager: EntityManager): Promise<string>;
18
+ add(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
19
+ AddActionConfigJson(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
20
+ getParameterizedNode(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
21
+ executeActionJson(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
22
+ }
23
+ export default Node;