@pxp-nd/flow 1.0.47 → 1.0.49

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.
@@ -11,6 +11,8 @@
11
11
  * 08-Jul-2021 Jaime Rivera Created
12
12
  * 18-Jul-2023 SP28JUL23 Mercedes Zambrana Add deleteFlow, saveFlowName, duplicateFlow
13
13
  * 02-Aug-2023 SP11AUG23 Mercedes Zambrana Add validations in deleteFlow and saveFlow
14
+ * 15-Aug-2023 SP25AUG23 Rensi Arteaga Add logic to duplicate flows templates
15
+ * 17-Aug-2023 SP25AUG23 Mercedes Zambrana Add insertEventFlow
14
16
  * ******************************************************************************
15
17
  */
16
18
  import { EntityManager } from 'typeorm';
@@ -28,5 +30,6 @@ declare class Flow extends Controller {
28
30
  saveFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
29
31
  getFlowRender(params: Record<string, any>): Promise<unknown>;
30
32
  sortNodesByConnections(nodes: any[], connections: any[]): any[];
33
+ insertEventFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
31
34
  }
32
35
  export default Flow;
@@ -12,6 +12,8 @@
12
12
  * 08-Jul-2021 Jaime Rivera Created
13
13
  * 18-Jul-2023 SP28JUL23 Mercedes Zambrana Add deleteFlow, saveFlowName, duplicateFlow
14
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-Aug-2023 SP25AUG23 Mercedes Zambrana Add insertEventFlow
15
17
  * ******************************************************************************
16
18
  */
17
19
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -151,7 +153,14 @@ let Flow = class Flow extends core_1.Controller {
151
153
  nodes: [],
152
154
  createdAt: undefined
153
155
  };
154
- const flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
156
+ let flowDataClone;
157
+ //if we have a vendoId as parameter the origin is a template
158
+ if (params.vendorId) {
159
+ flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${params.name}`, vendorId: params.vendorId, type: 'custom' });
160
+ }
161
+ else {
162
+ flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
163
+ }
155
164
  const nodesToDuplicate = await manager.find(Node_1.default, { flowId: flowData === null || flowData === void 0 ? void 0 : flowData.flowId, isActive: true });
156
165
  if (nodesToDuplicate) {
157
166
  const originalNodeIds = nodesToDuplicate.map((node) => node.nodeId);
@@ -175,7 +184,7 @@ let Flow = class Flow extends core_1.Controller {
175
184
  });
176
185
  await manager.save(duplicatedConnections);
177
186
  }
178
- return { success: true };
187
+ return { success: true, flowId: flowDataClone.flowId };
179
188
  }
180
189
  else {
181
190
  return { success: false, "respuesta": "No Flow" };
@@ -289,6 +298,25 @@ let Flow = class Flow extends core_1.Controller {
289
298
  return { success: true, nodeId: newId };
290
299
  }
291
300
  async getFlowRender(params) {
301
+ var _a;
302
+ const totalNodes = await (0, typeorm_1.getManager)()
303
+ .createQueryBuilder(Node_1.default, "n")
304
+ .select([
305
+ "n.nodeId",
306
+ "a.originName"
307
+ ])
308
+ .innerJoin("n.action", "a")
309
+ .where(`n.isActive = 1 and n.flowId = :flowId`, { flowId: params.flowId })
310
+ .getOne();
311
+ let cond = " and 0=0";
312
+ if (!totalNodes) {
313
+ cond = " and at.name= 'EVENT' ";
314
+ }
315
+ else {
316
+ const oName = (_a = totalNodes === null || totalNodes === void 0 ? void 0 : totalNodes.action) === null || _a === void 0 ? void 0 : _a.originName;
317
+ //
318
+ cond = `and at.name != 'EVENT' and (a.originName is null or a.originName = '${oName}')`;
319
+ }
292
320
  let actions = await (0, typeorm_1.getManager)()
293
321
  .createQueryBuilder(Action_1.default, "a")
294
322
  .select([
@@ -299,7 +327,7 @@ let Flow = class Flow extends core_1.Controller {
299
327
  "at.name"
300
328
  ])
301
329
  .innerJoin("a.actionType", "at")
302
- .where(`a.isActive = 1 and a.hidden = 'N'`)
330
+ .where(`a.isActive = 1 and a.hidden = 'N'` + cond)
303
331
  .getMany();
304
332
  const connections = await (0, typeorm_1.getManager)()
305
333
  .createQueryBuilder(NodeConnection_1.default, "nc")
@@ -391,6 +419,42 @@ let Flow = class Flow extends core_1.Controller {
391
419
  });
392
420
  return sortedNodes;
393
421
  }
422
+ async insertEventFlow(params, manager) {
423
+ let dataFlow = await (0, core_1.__)(Flow_1.default.findOne(params.flowId));
424
+ if (dataFlow) {
425
+ let action = await (0, typeorm_1.getManager)()
426
+ .createQueryBuilder(Action_1.default, "a")
427
+ .select([
428
+ "a.actionId"
429
+ ])
430
+ .innerJoin("a.actionType", "at")
431
+ .where(`a.isActive = 1 and a.hidden = 'N' and at.name = 'EVENT' and at.isActive = 1 `, { actionId: params.actionId })
432
+ .getMany();
433
+ if (action) {
434
+ const newNode = manager.create(Node_1.default, {
435
+ nodeId: undefined,
436
+ flowId: params.flowId,
437
+ isInit: 'N',
438
+ actionId: params.actionId
439
+ });
440
+ const saveNode = await manager.save(newNode);
441
+ const id = saveNode.nodeId;
442
+ const newConnection = manager.create(NodeConnection_1.default, {
443
+ nodeConnectionId: undefined,
444
+ nodeIdMaster: null,
445
+ nodeIdChild: id,
446
+ });
447
+ const savedNodes = await manager.save(newConnection);
448
+ return { success: true, nodeId: id };
449
+ }
450
+ else {
451
+ return { success: false, msg: "Action not found or is not event type" };
452
+ }
453
+ }
454
+ else {
455
+ return { success: false, msg: "Flow not found" };
456
+ }
457
+ }
394
458
  };
395
459
  __decorate([
396
460
  (0, core_1.Get)(),
@@ -455,6 +519,15 @@ __decorate([
455
519
  __metadata("design:paramtypes", [Object]),
456
520
  __metadata("design:returntype", Promise)
457
521
  ], Flow.prototype, "getFlowRender", null);
522
+ __decorate([
523
+ (0, core_1.Post)(),
524
+ (0, core_1.DbSettings)('Orm'),
525
+ (0, core_1.ReadOnly)(false),
526
+ (0, core_1.Log)(true),
527
+ __metadata("design:type", Function),
528
+ __metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
529
+ __metadata("design:returntype", Promise)
530
+ ], Flow.prototype, "insertEventFlow", null);
458
531
  Flow = __decorate([
459
532
  (0, core_1.Model)('flow-nd/Flow')
460
533
  ], Flow);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,6 +38,7 @@
38
38
  "dependencies": {
39
39
  "@pxp-nd/common": "^1.1.4",
40
40
  "@pxp-nd/core": "^1.1.13",
41
+ "@pxp-nd/flow": "file:.yalc/@pxp-nd/flow",
41
42
  "axios": "^0.21.1",
42
43
  "lodash": "^4.17.21",
43
44
  "typeorm": "^0.2.36"