@pxp-nd/flow 1.0.32 → 1.0.35

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.
@@ -26,5 +26,6 @@ declare class Flow extends Controller {
26
26
  duplicateFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
27
27
  getFlowRender(params: Record<string, any>): Promise<unknown>;
28
28
  sortNodesByConnections(nodes: any[], connections: any[]): any[];
29
+ saveFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
29
30
  }
30
31
  export default Flow;
@@ -270,6 +270,81 @@ let Flow = class Flow extends core_1.Controller {
270
270
  });
271
271
  return sortedNodes;
272
272
  }
273
+ async saveFlow(params, manager) {
274
+ let nodeRefIds = params.board.columns['2-column-nodes-configured'].taskIds;
275
+ let nodes = params.board.tasks;
276
+ let masterId = null;
277
+ let id = null;
278
+ let flowId = null;
279
+ let taskIds = [];
280
+ for (const nodeId of nodeRefIds) {
281
+ // console.log ('node:',nodes[`${nodeId}`]);
282
+ if (nodes[`${nodeId}`]) {
283
+ flowId = nodes[`${nodeId}`].flowId;
284
+ if (nodeId != 'new') {
285
+ id = parseInt(nodeId.split("-")[1]);
286
+ taskIds.push(id);
287
+ }
288
+ const connectionsToDel = await manager.find(NodeConnection_1.default, {
289
+ where: { nodeIdChild: id }
290
+ });
291
+ if (connectionsToDel) {
292
+ //console.log("hay para eliminar---->", connectionsToDel);
293
+ const originalNodeCIds = connectionsToDel.map((node) => node.nodeConnectionId);
294
+ //console.log("eliminando: ", originalNodeCIds);
295
+ let flowNodeC = await typeorm_1.getManager().query(`DELETE
296
+ from twf_node_connection
297
+ WHERE node_connection_id = ${originalNodeCIds}`);
298
+ }
299
+ }
300
+ }
301
+ //If there are some nodes in node_connections after delete all records sent, to inactive node
302
+ let connectNoDel = await typeorm_1.getManager().query(`SELECT n.node_id
303
+ from twf_node_connection nd
304
+ inner join twf_node n on n.node_id = nd.node_id_child
305
+ WHERE n.flow_id= ${flowId}`);
306
+ const currentNodesIds = connectNoDel.map((record) => record.node_id);
307
+ // Get nodes to remove
308
+ const nodesToRemove = currentNodesIds.filter((nodeId) => !taskIds.includes(nodeId.toString()));
309
+ // Inactive nodes
310
+ if (nodesToRemove.length > 0) {
311
+ const delNodeConnect = await manager.delete(NodeConnection_1.default, { nodeIdChild: nodesToRemove[0] });
312
+ if (delNodeConnect) {
313
+ let dNode = `UPDATE twf_node SET
314
+ is_active = 'N' WHERE node_id = ${nodesToRemove[0]}`;
315
+ await manager.query(dNode);
316
+ }
317
+ }
318
+ for (const nodeId of nodeRefIds) {
319
+ if (nodes[`${nodeId}`]) {
320
+ if (nodeId === 'new') {
321
+ //get information about Action
322
+ const newAction = await Action_1.default.findOne({ code: nodes[`${nodeId}`].action.code });
323
+ const newNode = manager.create(Node_1.default, {
324
+ nodeId: undefined,
325
+ flowId: nodes[`${nodeId}`].flowId,
326
+ isInit: 'N',
327
+ actionId: newAction.actionId
328
+ });
329
+ const saveNode = await manager.save(newNode);
330
+ id = saveNode.nodeId;
331
+ }
332
+ else {
333
+ id = parseInt(nodeId.split("-")[1]);
334
+ }
335
+ //save in node and node_connection
336
+ const newConnection = manager.create(NodeConnection_1.default, {
337
+ nodeConnectionId: undefined,
338
+ nodeIdMaster: masterId,
339
+ nodeIdChild: id,
340
+ });
341
+ masterId = id;
342
+ const savedNodes = await manager.save(newConnection);
343
+ // }
344
+ }
345
+ }
346
+ return { success: true };
347
+ }
273
348
  };
274
349
  __decorate([
275
350
  core_1.Get(),
@@ -325,6 +400,15 @@ __decorate([
325
400
  __metadata("design:paramtypes", [Object]),
326
401
  __metadata("design:returntype", Promise)
327
402
  ], Flow.prototype, "getFlowRender", null);
403
+ __decorate([
404
+ core_1.Post(),
405
+ core_1.DbSettings('Orm'),
406
+ core_1.ReadOnly(false),
407
+ core_1.Log(true),
408
+ __metadata("design:type", Function),
409
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
410
+ __metadata("design:returntype", Promise)
411
+ ], Flow.prototype, "saveFlow", null);
328
412
  Flow = __decorate([
329
413
  core_1.Model('flow-nd/Flow')
330
414
  ], Flow);
@@ -39,13 +39,13 @@ let Event = class Event {
39
39
  console.log("entra");
40
40
  //todo investigate replace variables into condition
41
41
  const newEvent = event.entity;
42
- const node = await core_1.__(Node_1.default.find({ where: { actionId: newEvent.actionId } }));
42
+ const node = await core_1.__(Node_1.default.find({ where: { actionId: newEvent.actionId, isActive: 1 } }));
43
43
  for (const n of node) {
44
44
  //get data of view
45
45
  const { action: { originName, originKey }, } = n;
46
46
  const executeView = `select * from ${originName} where ${originKey} = ${newEvent.dataId}`;
47
47
  const resExecuteView = await typeorm_1.getManager().query(executeView);
48
- const flow = await core_1.__(Flow_1.default.findOne({ where: { flowId: n.flowId } }));
48
+ const flow = await core_1.__(Flow_1.default.findOne({ where: { flowId: n.flowId, isActive: 1 } }));
49
49
  if (flow.vendorId == resExecuteView[0].vendor_id &&
50
50
  (await this.checkConditions(resExecuteView[0], n.flowId, newEvent.actionId))) {
51
51
  //now check all conditions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.32",
3
+ "version": "1.0.35",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",