@pxp-nd/flow 1.0.43 → 1.0.46
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 -1
- package/dist/controllers/Flow.js +131 -102
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* * -------------- ----------- -------------- ------------------------------------
|
|
11
11
|
* 08-Jul-2021 Jaime Rivera Created
|
|
12
12
|
* 18-Jul-2023 SP28JUL23 Mercedes Zambrana Add deleteFlow, saveFlowName, duplicateFlow
|
|
13
|
+
* 02-Aug-2023 SP11AUG23 Mercedes Zambrana Add validations in deleteFlow and saveFlow
|
|
13
14
|
* ******************************************************************************
|
|
14
15
|
*/
|
|
15
16
|
import { EntityManager } from 'typeorm';
|
|
@@ -24,8 +25,8 @@ declare class Flow extends Controller {
|
|
|
24
25
|
deleteFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
25
26
|
saveFlowName(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
26
27
|
duplicateFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
28
|
+
saveFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
27
29
|
getFlowRender(params: Record<string, any>): Promise<unknown>;
|
|
28
30
|
sortNodesByConnections(nodes: any[], connections: any[]): any[];
|
|
29
|
-
saveFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
30
31
|
}
|
|
31
32
|
export default Flow;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* * -------------- ----------- -------------- ------------------------------------
|
|
12
12
|
* 08-Jul-2021 Jaime Rivera Created
|
|
13
13
|
* 18-Jul-2023 SP28JUL23 Mercedes Zambrana Add deleteFlow, saveFlowName, duplicateFlow
|
|
14
|
+
* 02-Aug-2023 SP11AUG23 Mercedes Zambrana Add validations in deleteFlow and saveFlow
|
|
14
15
|
* ******************************************************************************
|
|
15
16
|
*/
|
|
16
17
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
@@ -103,18 +104,23 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
103
104
|
let flowInstance = `UPDATE twf_flow_instance SET
|
|
104
105
|
is_active = 'N' WHERE flow_id = ${updFlow.flowId}`;
|
|
105
106
|
await manager.query(flowInstance);
|
|
106
|
-
|
|
107
|
+
const nodesToInact = await manager.find(Node_1.default, { flowId: updFlow.flowId, isActive: true });
|
|
108
|
+
if (nodesToInact.length > 0) {
|
|
109
|
+
let flowNode = `UPDATE twf_node SET
|
|
107
110
|
is_active = 'N' WHERE flow_id = ${updFlow.flowId}`;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
await manager.query(flowNode);
|
|
112
|
+
const nodesToInact = await manager.find(Node_1.default, { flowId: updFlow.flowId });
|
|
113
|
+
const originalNodeIds = nodesToInact.map((node) => node.nodeId);
|
|
114
|
+
const connectionsToInact = await manager.find(NodeConnection_1.default, {
|
|
115
|
+
where: { nodeIdChild: (0, typeorm_1.In)(originalNodeIds) } // Suponiendo que originalNodeIds contiene los IDs de los nodos originales que deseas duplicar
|
|
116
|
+
});
|
|
117
|
+
const originalNodeCIds = connectionsToInact.map((node) => node.nodeConnectionId);
|
|
118
|
+
if (originalNodeCIds.length > 0) {
|
|
119
|
+
let flowNodeC = `UPDATE twf_node_connection SET
|
|
116
120
|
is_active = 'N' WHERE node_connection_id in ( ${originalNodeCIds})`;
|
|
117
|
-
|
|
121
|
+
await manager.query(flowNodeC);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
118
124
|
return { success: true };
|
|
119
125
|
}
|
|
120
126
|
else {
|
|
@@ -175,6 +181,113 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
175
181
|
return { success: false, "respuesta": "No Flow" };
|
|
176
182
|
}
|
|
177
183
|
}
|
|
184
|
+
async saveFlow(params, manager) {
|
|
185
|
+
let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
|
|
186
|
+
let nodes = params.board.tasks ? params.board.tasks : [];
|
|
187
|
+
let masterId = null;
|
|
188
|
+
let id = null;
|
|
189
|
+
let newId = null;
|
|
190
|
+
let flowId = null;
|
|
191
|
+
let taskIds = [];
|
|
192
|
+
if (nodeRefIds.length === 0) {
|
|
193
|
+
let nodeDelIdd = parseInt(params.board.deleteId.split("-")[1]);
|
|
194
|
+
const lastNoded = await Node_1.default.findOne({
|
|
195
|
+
where: {
|
|
196
|
+
nodeId: nodeDelIdd
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
flowId = lastNoded.flowId;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
flowId = params.board.flowId;
|
|
203
|
+
for (const nodeId of nodeRefIds) {
|
|
204
|
+
if (nodeId != 'new') {
|
|
205
|
+
id = parseInt(nodeId.split("node-")[1]);
|
|
206
|
+
if (!id) {
|
|
207
|
+
const lastNode = await Node_1.default.findOne({
|
|
208
|
+
where: {
|
|
209
|
+
flowId: flowId,
|
|
210
|
+
},
|
|
211
|
+
order: {
|
|
212
|
+
nodeId: 'DESC', // Ordena por ID en orden descendente para obtener el último registro
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
id = lastNode.nodeId;
|
|
216
|
+
}
|
|
217
|
+
taskIds.push(id);
|
|
218
|
+
const connectionsToDel = await manager.find(NodeConnection_1.default, {
|
|
219
|
+
where: { nodeIdChild: id }
|
|
220
|
+
});
|
|
221
|
+
if (connectionsToDel) {
|
|
222
|
+
const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
|
|
223
|
+
let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
|
|
224
|
+
from twf_node_connection
|
|
225
|
+
WHERE node_connection_id = ${originalNodeCIds}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
taskIds.push('new');
|
|
230
|
+
}
|
|
231
|
+
//}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (params.board.origin == 'deleteTask') {
|
|
235
|
+
let nodeDelId = parseInt(params.board.deleteId.split("-")[1]);
|
|
236
|
+
if (nodeDelId) {
|
|
237
|
+
//If there are some nodes in node_connections after delete all records sent, to inactive node
|
|
238
|
+
let connectNoDel = await (0, typeorm_1.getManager)().query(`SELECT n.node_id
|
|
239
|
+
from twf_node_connection nd
|
|
240
|
+
inner join twf_node n on n.node_id = nd.node_id_child
|
|
241
|
+
WHERE n.node_id = ${nodeDelId}`);
|
|
242
|
+
const currentNodesIds = connectNoDel.map((record) => record.node_id);
|
|
243
|
+
// Get nodes to remove
|
|
244
|
+
const nodesToRemove = currentNodesIds.filter((nodeId) => !taskIds.includes(nodeId.toString()));
|
|
245
|
+
// Inactive nodes
|
|
246
|
+
if (nodesToRemove.length > 0) {
|
|
247
|
+
const delNodeConnect = await manager.delete(NodeConnection_1.default, { nodeIdChild: nodesToRemove[0] });
|
|
248
|
+
if (delNodeConnect) {
|
|
249
|
+
let dNode = `UPDATE twf_node
|
|
250
|
+
SET is_active = 'N'
|
|
251
|
+
WHERE node_id = ${nodesToRemove[0]}`;
|
|
252
|
+
await manager.query(dNode);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (nodeRefIds.length === 0) {
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
for (const nodeId of taskIds) {
|
|
261
|
+
if (nodeId === 'new') {
|
|
262
|
+
//get information about Action
|
|
263
|
+
const newAction = await Action_1.default.findOne({ code: nodes[`${nodeId}`].action.code });
|
|
264
|
+
const newNode = manager.create(Node_1.default, {
|
|
265
|
+
nodeId: undefined,
|
|
266
|
+
flowId: nodes[`${nodeId}`].flowId,
|
|
267
|
+
isInit: 'N',
|
|
268
|
+
actionId: newAction.actionId
|
|
269
|
+
});
|
|
270
|
+
const saveNode = await manager.save(newNode);
|
|
271
|
+
id = saveNode.nodeId;
|
|
272
|
+
newId = saveNode.nodeId;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
id = nodeId;
|
|
276
|
+
}
|
|
277
|
+
//save in node and node_connection
|
|
278
|
+
const newConnection = manager.create(NodeConnection_1.default, {
|
|
279
|
+
nodeConnectionId: undefined,
|
|
280
|
+
nodeIdMaster: masterId,
|
|
281
|
+
nodeIdChild: id,
|
|
282
|
+
});
|
|
283
|
+
masterId = id;
|
|
284
|
+
const savedNodes = await manager.save(newConnection);
|
|
285
|
+
// }
|
|
286
|
+
}
|
|
287
|
+
//}
|
|
288
|
+
}
|
|
289
|
+
return { success: true, nodeId: newId };
|
|
290
|
+
}
|
|
178
291
|
async getFlowRender(params) {
|
|
179
292
|
let actions = await (0, typeorm_1.getManager)()
|
|
180
293
|
.createQueryBuilder(Action_1.default, "a")
|
|
@@ -277,90 +390,6 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
277
390
|
});
|
|
278
391
|
return sortedNodes;
|
|
279
392
|
}
|
|
280
|
-
async saveFlow(params, manager) {
|
|
281
|
-
let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
|
|
282
|
-
let nodes = params.board.tasks;
|
|
283
|
-
let masterId = null;
|
|
284
|
-
let id = null;
|
|
285
|
-
let flowId = null;
|
|
286
|
-
let taskIds = [];
|
|
287
|
-
if (nodeRefIds.length === 0) {
|
|
288
|
-
flowId = params.board.columns['2-column-nodes-configured'].flowId;
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
for (const nodeId of nodeRefIds) {
|
|
292
|
-
// console.log ('node:',nodes[`${nodeId}`]);
|
|
293
|
-
if (nodes[`${nodeId}`]) {
|
|
294
|
-
flowId = nodes[`${nodeId}`].flowId;
|
|
295
|
-
if (nodeId != 'new') {
|
|
296
|
-
id = parseInt(nodeId.split("-")[1]);
|
|
297
|
-
taskIds.push(id);
|
|
298
|
-
const connectionsToDel = await manager.find(NodeConnection_1.default, {
|
|
299
|
-
where: { nodeIdChild: id }
|
|
300
|
-
});
|
|
301
|
-
if (connectionsToDel) {
|
|
302
|
-
//console.log("hay para eliminar---->", connectionsToDel);
|
|
303
|
-
const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
|
|
304
|
-
//console.log("eliminando: ", originalNodeCIds);
|
|
305
|
-
let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
|
|
306
|
-
from twf_node_connection
|
|
307
|
-
WHERE node_connection_id = ${originalNodeCIds}`);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
//If there are some nodes in node_connections after delete all records sent, to inactive node
|
|
314
|
-
let connectNoDel = await (0, typeorm_1.getManager)().query(`SELECT n.node_id
|
|
315
|
-
from twf_node_connection nd
|
|
316
|
-
inner join twf_node n on n.node_id = nd.node_id_child
|
|
317
|
-
WHERE n.flow_id= ${flowId}`);
|
|
318
|
-
const currentNodesIds = connectNoDel.map((record) => record.node_id);
|
|
319
|
-
// Get nodes to remove
|
|
320
|
-
const nodesToRemove = currentNodesIds.filter((nodeId) => !taskIds.includes(nodeId.toString()));
|
|
321
|
-
// Inactive nodes
|
|
322
|
-
if (nodesToRemove.length > 0) {
|
|
323
|
-
const delNodeConnect = await manager.delete(NodeConnection_1.default, { nodeIdChild: nodesToRemove[0] });
|
|
324
|
-
if (delNodeConnect) {
|
|
325
|
-
let dNode = `UPDATE twf_node SET
|
|
326
|
-
is_active = 'N' WHERE node_id = ${nodesToRemove[0]}`;
|
|
327
|
-
await manager.query(dNode);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (nodeRefIds.length === 0) {
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
for (const nodeId of nodeRefIds) {
|
|
334
|
-
if (nodes[`${nodeId}`]) {
|
|
335
|
-
if (nodeId === 'new') {
|
|
336
|
-
//get information about Action
|
|
337
|
-
const newAction = await Action_1.default.findOne({ code: nodes[`${nodeId}`].action.code });
|
|
338
|
-
const newNode = manager.create(Node_1.default, {
|
|
339
|
-
nodeId: undefined,
|
|
340
|
-
flowId: nodes[`${nodeId}`].flowId,
|
|
341
|
-
isInit: 'N',
|
|
342
|
-
actionId: newAction.actionId
|
|
343
|
-
});
|
|
344
|
-
const saveNode = await manager.save(newNode);
|
|
345
|
-
id = saveNode.nodeId;
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
id = parseInt(nodeId.split("-")[1]);
|
|
349
|
-
}
|
|
350
|
-
//save in node and node_connection
|
|
351
|
-
const newConnection = manager.create(NodeConnection_1.default, {
|
|
352
|
-
nodeConnectionId: undefined,
|
|
353
|
-
nodeIdMaster: masterId,
|
|
354
|
-
nodeIdChild: id,
|
|
355
|
-
});
|
|
356
|
-
masterId = id;
|
|
357
|
-
const savedNodes = await manager.save(newConnection);
|
|
358
|
-
// }
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return { success: true };
|
|
363
|
-
}
|
|
364
393
|
};
|
|
365
394
|
__decorate([
|
|
366
395
|
(0, core_1.Get)(),
|
|
@@ -408,23 +437,23 @@ __decorate([
|
|
|
408
437
|
__metadata("design:returntype", Promise)
|
|
409
438
|
], Flow.prototype, "duplicateFlow", null);
|
|
410
439
|
__decorate([
|
|
411
|
-
(0, core_1.
|
|
440
|
+
(0, core_1.Post)(),
|
|
412
441
|
(0, core_1.DbSettings)('Orm'),
|
|
413
|
-
(0, core_1.ReadOnly)(
|
|
442
|
+
(0, core_1.ReadOnly)(false),
|
|
414
443
|
(0, core_1.Log)(true),
|
|
415
444
|
__metadata("design:type", Function),
|
|
416
|
-
__metadata("design:paramtypes", [Object]),
|
|
445
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
417
446
|
__metadata("design:returntype", Promise)
|
|
418
|
-
], Flow.prototype, "
|
|
447
|
+
], Flow.prototype, "saveFlow", null);
|
|
419
448
|
__decorate([
|
|
420
|
-
(0, core_1.
|
|
449
|
+
(0, core_1.Get)(),
|
|
421
450
|
(0, core_1.DbSettings)('Orm'),
|
|
422
|
-
(0, core_1.ReadOnly)(
|
|
451
|
+
(0, core_1.ReadOnly)(true),
|
|
423
452
|
(0, core_1.Log)(true),
|
|
424
453
|
__metadata("design:type", Function),
|
|
425
|
-
__metadata("design:paramtypes", [Object
|
|
454
|
+
__metadata("design:paramtypes", [Object]),
|
|
426
455
|
__metadata("design:returntype", Promise)
|
|
427
|
-
], Flow.prototype, "
|
|
456
|
+
], Flow.prototype, "getFlowRender", null);
|
|
428
457
|
Flow = __decorate([
|
|
429
458
|
(0, core_1.Model)('flow-nd/Flow')
|
|
430
459
|
], Flow);
|