@pxp-nd/flow 1.0.43 → 1.0.45

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.
@@ -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;
@@ -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
- let flowNode = `UPDATE twf_node SET
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
- await manager.query(flowNode);
109
- const nodesToInact = await manager.find(Node_1.default, { flowId: updFlow.flowId });
110
- const originalNodeIds = nodesToInact.map((node) => node.nodeId);
111
- const connectionsToInact = await manager.find(NodeConnection_1.default, {
112
- where: { nodeIdChild: (0, typeorm_1.In)(originalNodeIds) } // Suponiendo que originalNodeIds contiene los IDs de los nodos originales que deseas duplicar
113
- });
114
- const originalNodeCIds = connectionsToInact.map((node) => node.nodeConnectionId);
115
- let flowNodeC = `UPDATE twf_node_connection SET
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
- await manager.query(flowNodeC);
121
+ await manager.query(flowNodeC);
122
+ }
123
+ }
118
124
  return { success: true };
119
125
  }
120
126
  else {
@@ -175,6 +181,104 @@ 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
+ console.log(params);
186
+ let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
187
+ console.log("nodesRef:", nodeRefIds);
188
+ let nodes = params.board.tasks ? params.board.tasks : [];
189
+ console.log("nod:", nodes);
190
+ let masterId = null;
191
+ let id = null;
192
+ let flowId = null;
193
+ let taskIds = [];
194
+ if (nodeRefIds.length === 0) {
195
+ flowId = params.board.columns['2-column-nodes-configured'].flowId;
196
+ }
197
+ else {
198
+ for (const nodeId of nodeRefIds) {
199
+ // console.log ('node:',nodes[`${nodeId}`]);
200
+ if (nodeId != 'new') {
201
+ id = parseInt(nodeId.split("-")[1]);
202
+ taskIds.push(id);
203
+ const connectionsToDel = await manager.find(NodeConnection_1.default, {
204
+ where: { nodeIdChild: id }
205
+ });
206
+ if (connectionsToDel) {
207
+ //console.log("hay para eliminar---->", connectionsToDel);
208
+ const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
209
+ //console.log("eliminando: ", originalNodeCIds);
210
+ let flowNodeC = await (0, typeorm_1.getManager)().query(`DELETE
211
+ from twf_node_connection
212
+ WHERE node_connection_id = ${originalNodeCIds}`);
213
+ }
214
+ }
215
+ //}
216
+ }
217
+ }
218
+ //if (nodes[`${nodeId}`]) {
219
+ //flowId = nodes[`${nodeId}`].flowId;
220
+ if (params.board.origin == 'deleteTask') {
221
+ console.log("aqui elimina", params.board.deleteID);
222
+ let nodeDelId = parseInt(params.board.deleteId.split("-")[1]);
223
+ console.log(nodeDelId);
224
+ if (nodeDelId) {
225
+ //If there are some nodes in node_connections after delete all records sent, to inactive node
226
+ let connectNoDel = await (0, typeorm_1.getManager)().query(`SELECT n.node_id
227
+ from twf_node_connection nd
228
+ inner join twf_node n on n.node_id = nd.node_id_child
229
+ WHERE n.node_id = ${nodeDelId}`);
230
+ const currentNodesIds = connectNoDel.map((record) => record.node_id);
231
+ // Get nodes to remove
232
+ const nodesToRemove = currentNodesIds.filter((nodeId) => !taskIds.includes(nodeId.toString()));
233
+ // Inactive nodes
234
+ if (nodesToRemove.length > 0) {
235
+ const delNodeConnect = await manager.delete(NodeConnection_1.default, { nodeIdChild: nodesToRemove[0] });
236
+ if (delNodeConnect) {
237
+ let dNode = `UPDATE twf_node
238
+ SET is_active = 'N'
239
+ WHERE node_id = ${nodesToRemove[0]}`;
240
+ await manager.query(dNode);
241
+ }
242
+ }
243
+ }
244
+ }
245
+ console.log("aqui tiene q entrar a volver a insertar");
246
+ //armamos las relaciones
247
+ if (nodeRefIds.length === 0) {
248
+ }
249
+ else {
250
+ for (const nodeId of nodeRefIds) {
251
+ // if (nodes[`${nodeId}`]) {
252
+ if (nodeId === 'new') {
253
+ //get information about Action
254
+ const newAction = await Action_1.default.findOne({ code: nodes[`${nodeId}`].action.code });
255
+ const newNode = manager.create(Node_1.default, {
256
+ nodeId: undefined,
257
+ flowId: nodes[`${nodeId}`].flowId,
258
+ isInit: 'N',
259
+ actionId: newAction.actionId
260
+ });
261
+ const saveNode = await manager.save(newNode);
262
+ id = saveNode.nodeId;
263
+ }
264
+ else {
265
+ id = parseInt(nodeId.split("-")[1]);
266
+ }
267
+ //save in node and node_connection
268
+ const newConnection = manager.create(NodeConnection_1.default, {
269
+ nodeConnectionId: undefined,
270
+ nodeIdMaster: masterId,
271
+ nodeIdChild: id,
272
+ });
273
+ masterId = id;
274
+ const savedNodes = await manager.save(newConnection);
275
+ // }
276
+ }
277
+ //}
278
+ }
279
+ console.log("fin de funcion");
280
+ return { success: true };
281
+ }
178
282
  async getFlowRender(params) {
179
283
  let actions = await (0, typeorm_1.getManager)()
180
284
  .createQueryBuilder(Action_1.default, "a")
@@ -277,90 +381,6 @@ let Flow = class Flow extends core_1.Controller {
277
381
  });
278
382
  return sortedNodes;
279
383
  }
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
384
  };
365
385
  __decorate([
366
386
  (0, core_1.Get)(),
@@ -408,23 +428,23 @@ __decorate([
408
428
  __metadata("design:returntype", Promise)
409
429
  ], Flow.prototype, "duplicateFlow", null);
410
430
  __decorate([
411
- (0, core_1.Get)(),
431
+ (0, core_1.Post)(),
412
432
  (0, core_1.DbSettings)('Orm'),
413
- (0, core_1.ReadOnly)(true),
433
+ (0, core_1.ReadOnly)(false),
414
434
  (0, core_1.Log)(true),
415
435
  __metadata("design:type", Function),
416
- __metadata("design:paramtypes", [Object]),
436
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
417
437
  __metadata("design:returntype", Promise)
418
- ], Flow.prototype, "getFlowRender", null);
438
+ ], Flow.prototype, "saveFlow", null);
419
439
  __decorate([
420
- (0, core_1.Post)(),
440
+ (0, core_1.Get)(),
421
441
  (0, core_1.DbSettings)('Orm'),
422
- (0, core_1.ReadOnly)(false),
442
+ (0, core_1.ReadOnly)(true),
423
443
  (0, core_1.Log)(true),
424
444
  __metadata("design:type", Function),
425
- __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
445
+ __metadata("design:paramtypes", [Object]),
426
446
  __metadata("design:returntype", Promise)
427
- ], Flow.prototype, "saveFlow", null);
447
+ ], Flow.prototype, "getFlowRender", null);
428
448
  Flow = __decorate([
429
449
  (0, core_1.Model)('flow-nd/Flow')
430
450
  ], Flow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",