@pxp-nd/flow 1.0.66 → 1.0.68

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.
@@ -22,7 +22,7 @@ import { Controller } from '@pxp-nd/core';
22
22
  declare class Flow extends Controller {
23
23
  get(params: Record<string, any>): Promise<unknown>;
24
24
  copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager): Promise<void>;
25
- copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager): Promise<{
25
+ copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager, isFirst?: boolean): Promise<{
26
26
  nodeId: any;
27
27
  }>;
28
28
  createFlowFromFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
@@ -62,7 +62,7 @@ let Flow = class Flow extends core_1.Controller {
62
62
  return restNodes;
63
63
  }
64
64
  async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
65
- const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId }));
65
+ const connections = await (0, core_1.__)(NodeConnection_1.default.find({ nodeIdMaster: nodeId, isActive: true }));
66
66
  for (let connection of connections) {
67
67
  const newNodeConnection = new NodeConnection_1.default();
68
68
  const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
@@ -73,12 +73,19 @@ let Flow = class Flow extends core_1.Controller {
73
73
  const insertNewNodeConnection = await (0, core_1.__)(manager.save(NodeConnection_1.default, newNodeConnection));
74
74
  }
75
75
  }
76
- async copyNode(node, newFlowId, manager) {
76
+ async copyNode(node, newFlowId, manager, isFirst = false) {
77
77
  // insert new node
78
78
  const newNode = new Node_1.default();
79
79
  const { nodeId, flowId, createdAt, modifiedAt, actionConfigJson, ...nodeToCopy } = node;
80
80
  Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
81
81
  const insertNewNode = await (0, core_1.__)(manager.save(Node_1.default, newNode));
82
+ if (isFirst) {
83
+ const duplicatedConnection = manager.create(NodeConnection_1.default, {
84
+ nodeConnectionId: undefined,
85
+ nodeIdMaster: undefined,
86
+ nodeIdChild: insertNewNode.nodeId,
87
+ });
88
+ }
82
89
  // insert connection
83
90
  await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
84
91
  return { nodeId: insertNewNode.nodeId };
@@ -160,7 +167,8 @@ let Flow = class Flow extends core_1.Controller {
160
167
  ...flowData,
161
168
  flowId: undefined,
162
169
  nodes: [],
163
- createdAt: undefined,
170
+ createdAt: new Date(),
171
+ modifiedAt: new Date(),
164
172
  status: 'off'
165
173
  };
166
174
  let flowDataClone;
@@ -171,29 +179,8 @@ let Flow = class Flow extends core_1.Controller {
171
179
  else {
172
180
  flowDataClone = await manager.save(Flow_1.default, { ...flowToClone, name: `${flowData.name} Copy` });
173
181
  }
174
- const nodesToDuplicate = await manager.find(Node_1.default, { flowId: flowData === null || flowData === void 0 ? void 0 : flowData.flowId, isActive: true });
175
- if (nodesToDuplicate) {
176
- const originalNodeIds = nodesToDuplicate.map((node) => node.nodeId);
177
- const duplicatedNodes = nodesToDuplicate.map((node) => {
178
- const duplicatedNode = manager.create(Node_1.default, { ...node, nodeId: undefined });
179
- duplicatedNode.flowId = flowDataClone.flowId;
180
- return duplicatedNode;
181
- });
182
- const savedNodes = await manager.save(duplicatedNodes);
183
- const newNodeIds = savedNodes.map((node) => node.nodeId);
184
- const connectionsToDuplicate = await manager.find(NodeConnection_1.default, {
185
- where: { nodeIdChild: (0, typeorm_1.In)(originalNodeIds), isActive: true }
186
- });
187
- const duplicatedConnections = newNodeIds.map((nodeId, index) => {
188
- const duplicatedConnection = manager.create(NodeConnection_1.default, {
189
- nodeConnectionId: undefined,
190
- nodeIdMaster: index === 0 ? null : newNodeIds[index - 1],
191
- nodeIdChild: nodeId,
192
- });
193
- return duplicatedConnection;
194
- });
195
- await manager.save(duplicatedConnections);
196
- }
182
+ const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId, isInit: 'Y', isActive: true }, order: { nodeId: "ASC" } });
183
+ dataNode && await this.copyNode(dataNode, flowDataClone.flowId, manager, true);
197
184
  return { success: true, flowId: flowDataClone.flowId };
198
185
  }
199
186
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",