@pxp-nd/flow 1.0.20 → 1.0.24

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.
@@ -29,8 +29,10 @@ const typeorm_1 = require("typeorm");
29
29
  const Node_1 = __importDefault(require("../entity/Node"));
30
30
  const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
31
31
  const core_1 = require("@pxp-nd/core");
32
+ const lodash_1 = __importDefault(require("lodash"));
32
33
  const FieldMap_1 = __importDefault(require("../entity/FieldMap"));
33
34
  const OriginName_1 = __importDefault(require("../entity/OriginName"));
35
+ const axios_1 = __importDefault(require("axios"));
34
36
  let Node = class Node extends core_1.Controller {
35
37
  async getNodeData(node, dataId, manager) {
36
38
  const { action: { originName, originKey } } = node;
@@ -79,20 +81,22 @@ let Node = class Node extends core_1.Controller {
79
81
  };
80
82
  }
81
83
  async getParameterizedNode(params, manager) {
82
- const { nodeId, flowId } = params;
83
- /*const tNodeOrigin = __(NodeModel.find({
84
- relations: ['action'],
85
- where: {
86
- flowId: flowId,
87
- action: {
88
- originName: Not(IsNull())
84
+ lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
85
+ const { nodeId, flowId, substitutionsSchemaJson } = params;
86
+ const tNodeOrigin = await core_1.__(Node_1.default.findOne({
87
+ relations: ['action'],
88
+ where: {
89
+ flowId: flowId,
90
+ isInit: 'Y',
91
+ action: {
92
+ originName: typeorm_1.Not(typeorm_1.IsNull())
93
+ }
89
94
  }
90
- }
91
- }));*/
95
+ }));
92
96
  const tNodeData = core_1.__(Node_1.default.findOne(nodeId));
93
97
  const tFieldMapData = core_1.__(manager.createQueryBuilder(FieldMap_1.default, 'fm')
94
98
  .innerJoin(OriginName_1.default, 'on', 'on.originNameId = fm.originNameId')
95
- .where("on.name = :n ", { n: 'v_member' })
99
+ .where("on.name = :n ", { n: tNodeOrigin.action.originName })
96
100
  .getMany());
97
101
  //const nodeOrigin = await tNodeOrigin; todo
98
102
  const nodeData = await tNodeData;
@@ -101,10 +105,12 @@ let Node = class Node extends core_1.Controller {
101
105
  tNodeData,
102
106
  tFieldMapData
103
107
  ]);*/
104
- const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson } } } = nodeData;
108
+ const { actionConfigJson, action: { schemaJson, configJsonTemplate, actionType: { schemaJson: schemaJsonFromActionType } } } = nodeData;
105
109
  const actionConfigJsonObject = actionConfigJson ? JSON.parse(actionConfigJson) : {};
106
110
  const configJsonTemplateObject = configJsonTemplate ? JSON.parse(configJsonTemplate) : {};
107
- let schemaJsonObject = schemaJson ? JSON.parse(schemaJson) : {};
111
+ let schemaJsonFromActionTypeObject = schemaJsonFromActionType ? JSON.parse(lodash_1.default.template(schemaJsonFromActionType)(substitutionsSchemaJson)) : {};
112
+ let schemaJsonFromActionObject = schemaJson ? JSON.parse(lodash_1.default.template(schemaJson)(substitutionsSchemaJson)) : {};
113
+ let schemaJsonObject = { ...schemaJsonFromActionTypeObject, ...schemaJsonFromActionObject };
108
114
  const mergeValues = {
109
115
  ...configJsonTemplateObject,
110
116
  ...actionConfigJsonObject
@@ -122,15 +128,50 @@ let Node = class Node extends core_1.Controller {
122
128
  metadata: found
123
129
  };
124
130
  };
125
- Object.entries(mergeValues).forEach(([nameKey, value]) => {
131
+ // this logic is for autocomplete for moment
132
+ const findFieldInConfigForComponent = async (json, value) => {
133
+ console.log('json', json);
134
+ if (json.formComponent && json.formComponent.type === 'AutoComplete') {
135
+ console.log('json.formComponent', json.formComponent.store);
136
+ const url = json.formComponent.store.axios.url;
137
+ const method = json.formComponent.store.axios.method;
138
+ const data = json.formComponent.store.axios.data;
139
+ const idDD = json.formComponent.store.idDD;
140
+ const descDD = json.formComponent.store.descDD;
141
+ const config = {
142
+ method: method,
143
+ url: url,
144
+ headers: {
145
+ 'Authorization': '' + process.env.TOKEN_PXP_ND + '',
146
+ 'Content-Type': 'application/json'
147
+ },
148
+ data: {
149
+ ...data,
150
+ [idDD]: value
151
+ }
152
+ };
153
+ console.log('config', config);
154
+ // @ts-ignore
155
+ const resControllerAxios = await core_1.__(axios_1.default(config));
156
+ console.log('resControllerAxios', resControllerAxios.data.data);
157
+ console.log('resControllerAxios', resControllerAxios.data.data[descDD]);
158
+ const desc = resControllerAxios.data.data[descDD];
159
+ return desc;
160
+ }
161
+ return undefined;
162
+ };
163
+ for (const [nameKey, value] of Object.entries(mergeValues)) {
126
164
  if (schemaJsonObject[nameKey]) {
165
+ const descValue = await core_1.__(findFieldInConfigForComponent(schemaJsonObject[nameKey], value));
166
+ console.log('descValue', descValue);
127
167
  schemaJsonObject[nameKey] = {
128
168
  ...schemaJsonObject[nameKey],
129
169
  initialValue: value,
170
+ ...(descValue && { descValue: descValue }),
130
171
  ...(verifyIfValueFromFieldMap(value) && { fromFieldMap: true, ...findFieldMapAndMetaData(value) }),
131
172
  };
132
173
  }
133
- });
174
+ }
134
175
  return {
135
176
  actionConfigJsonObject,
136
177
  configJsonTemplateObject,
@@ -177,7 +218,7 @@ __decorate([
177
218
  __metadata("design:returntype", Promise)
178
219
  ], Node.prototype, "AddActionConfigJson", null);
179
220
  __decorate([
180
- core_1.Get(),
221
+ core_1.Post(),
181
222
  core_1.DbSettings('Orm'),
182
223
  core_1.ReadOnly(false),
183
224
  core_1.Log(true),
@@ -11,7 +11,9 @@ export default class Action extends PxpEntity {
11
11
  originKey: string;
12
12
  controllerFunction: string;
13
13
  configJsonTemplate: string;
14
+ eventConfig: string;
14
15
  hidden: string;
16
+ schemaJson: string;
15
17
  actionType: ActionType;
16
18
  nodes: Node[];
17
19
  eventNodes: Node[];
@@ -54,10 +54,18 @@ __decorate([
54
54
  typeorm_1.Column({ name: 'config_json_template', type: 'text' }),
55
55
  __metadata("design:type", String)
56
56
  ], Action.prototype, "configJsonTemplate", void 0);
57
+ __decorate([
58
+ typeorm_1.Column({ name: 'event_config', type: 'text' }),
59
+ __metadata("design:type", String)
60
+ ], Action.prototype, "eventConfig", void 0);
57
61
  __decorate([
58
62
  typeorm_1.Column({ type: 'varchar', nullable: false, length: 1, default: 'N' }),
59
63
  __metadata("design:type", String)
60
64
  ], Action.prototype, "hidden", void 0);
65
+ __decorate([
66
+ typeorm_1.Column({ name: 'schema_json', type: 'text' }),
67
+ __metadata("design:type", String)
68
+ ], Action.prototype, "schemaJson", void 0);
61
69
  __decorate([
62
70
  typeorm_1.ManyToOne(() => ActionType_1.default, actionType => actionType.actions, { eager: true }),
63
71
  typeorm_1.JoinColumn({ name: 'action_type_id' }),
@@ -17,4 +17,5 @@ import EventModel from '../entity/Event';
17
17
  export declare class Event implements EntitySubscriberInterface<EventModel> {
18
18
  listenTo(): typeof EventModel;
19
19
  afterInsert(event: InsertEvent<EventModel>): Promise<void>;
20
+ checkConditions(viewData: Record<string, any>, flowId: number, actionId: number): Promise<boolean>;
20
21
  }
@@ -27,6 +27,7 @@ exports.Event = void 0;
27
27
  const typeorm_1 = require("typeorm");
28
28
  const Event_1 = __importDefault(require("../entity/Event"));
29
29
  const Node_1 = __importDefault(require("../entity/Node"));
30
+ const Action_1 = __importDefault(require("../entity/Action"));
30
31
  const Flow_1 = __importDefault(require("../entity/Flow"));
31
32
  const core_1 = require("@pxp-nd/core");
32
33
  const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
@@ -45,7 +46,8 @@ let Event = class Event {
45
46
  const executeView = `select * from ${originName} where ${originKey} = ${newEvent.dataId}`;
46
47
  const resExecuteView = await typeorm_1.getManager().query(executeView);
47
48
  const flow = await core_1.__(Flow_1.default.findOne({ where: { flowId: n.flowId } }));
48
- if (flow.vendorId == resExecuteView[0].vendor_id) {
49
+ if (flow.vendorId == resExecuteView[0].vendor_id && this.checkConditions(resExecuteView[0], n.flowId, newEvent.actionId)) {
50
+ //now check all conditions
49
51
  let flowInstance = new FlowInstance_1.default();
50
52
  flowInstance.flowId = n.flowId;
51
53
  flowInstance.dataId = newEvent.dataId;
@@ -57,6 +59,23 @@ let Event = class Event {
57
59
  }
58
60
  }
59
61
  }
62
+ async checkConditions(viewData, flowId, actionId) {
63
+ const action = await Action_1.default.findOne(actionId);
64
+ const node = await Node_1.default.findOne({ where: { actionId, flowId } });
65
+ const actionConfigJson = JSON.parse(node.actionConfigJson);
66
+ let res = true;
67
+ if (action.eventConfig) {
68
+ const eventConfig = JSON.parse(action.eventConfig);
69
+ if (eventConfig.filters) {
70
+ eventConfig.filters.forEach((filter) => {
71
+ if (actionConfigJson[filter.nodeField] && viewData[filter.originField] != actionConfigJson[filter.nodeField]) {
72
+ res = false;
73
+ }
74
+ });
75
+ }
76
+ }
77
+ return res;
78
+ }
60
79
  };
61
80
  Event = __decorate([
62
81
  typeorm_1.EventSubscriber()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pxp-nd/flow",
3
- "version": "1.0.20",
3
+ "version": "1.0.24",
4
4
  "description": "Workflow module for pxp-nd framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",