@pxp-nd/flow 1.0.21 → 1.0.25
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.
package/dist/controllers/Flow.js
CHANGED
|
@@ -35,8 +35,22 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
35
35
|
const nodes = await Node_1.default.find({ flowId: params.flowId });
|
|
36
36
|
const restNodes = [];
|
|
37
37
|
for (let node of nodes) {
|
|
38
|
+
const { actionConfigJson, action: { actionType: { schemaJson } } } = node;
|
|
39
|
+
const actionConfigJsonObject = actionConfigJson ? JSON.parse(actionConfigJson) : {};
|
|
40
|
+
const schemaJsonObject = schemaJson ? JSON.parse(schemaJson) : {};
|
|
41
|
+
const valuesForShowingInNode = {};
|
|
42
|
+
Object.entries(schemaJsonObject).filter(([n, sjo]) => sjo.showInNode === true).forEach(([nameKey, json]) => {
|
|
43
|
+
valuesForShowingInNode[nameKey] = {
|
|
44
|
+
label: json.label,
|
|
45
|
+
value: actionConfigJsonObject[nameKey] || null
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
const nodeRow = {
|
|
49
|
+
...node,
|
|
50
|
+
valuesForShowingInNode
|
|
51
|
+
};
|
|
38
52
|
const connections = await NodeConnection_1.default.find({ nodeIdMaster: node.nodeId });
|
|
39
|
-
restNodes.push({ node, connections: connections.map(c => c.nodeIdChild) });
|
|
53
|
+
restNodes.push({ node: nodeRow, connections: connections.map(c => c.nodeIdChild) });
|
|
40
54
|
}
|
|
41
55
|
return restNodes;
|
|
42
56
|
}
|
package/dist/controllers/Node.js
CHANGED
|
@@ -32,6 +32,7 @@ const core_1 = require("@pxp-nd/core");
|
|
|
32
32
|
const lodash_1 = __importDefault(require("lodash"));
|
|
33
33
|
const FieldMap_1 = __importDefault(require("../entity/FieldMap"));
|
|
34
34
|
const OriginName_1 = __importDefault(require("../entity/OriginName"));
|
|
35
|
+
const axios_1 = __importDefault(require("axios"));
|
|
35
36
|
let Node = class Node extends core_1.Controller {
|
|
36
37
|
async getNodeData(node, dataId, manager) {
|
|
37
38
|
const { action: { originName, originKey } } = node;
|
|
@@ -81,20 +82,21 @@ let Node = class Node extends core_1.Controller {
|
|
|
81
82
|
}
|
|
82
83
|
async getParameterizedNode(params, manager) {
|
|
83
84
|
lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
84
|
-
const { nodeId, flowId, substitutionsSchemaJson } = params;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
|
91
94
|
}
|
|
92
|
-
|
|
93
|
-
}));*/
|
|
95
|
+
}));
|
|
94
96
|
const tNodeData = core_1.__(Node_1.default.findOne(nodeId));
|
|
95
97
|
const tFieldMapData = core_1.__(manager.createQueryBuilder(FieldMap_1.default, 'fm')
|
|
96
98
|
.innerJoin(OriginName_1.default, 'on', 'on.originNameId = fm.originNameId')
|
|
97
|
-
.where("on.name = :n ", { n:
|
|
99
|
+
.where("on.name = :n ", { n: tNodeOrigin.action.originName })
|
|
98
100
|
.getMany());
|
|
99
101
|
//const nodeOrigin = await tNodeOrigin; todo
|
|
100
102
|
const nodeData = await tNodeData;
|
|
@@ -126,14 +128,81 @@ let Node = class Node extends core_1.Controller {
|
|
|
126
128
|
metadata: found
|
|
127
129
|
};
|
|
128
130
|
};
|
|
129
|
-
|
|
131
|
+
const findFieldMapUniqueByType = (fieldMappingType) => {
|
|
132
|
+
const filtered = fieldMapData.filter((fmd) => fmd.type === fieldMappingType);
|
|
133
|
+
if (filtered && filtered.length === 1) {
|
|
134
|
+
const [found] = filtered;
|
|
135
|
+
return {
|
|
136
|
+
initialValue: found.alias,
|
|
137
|
+
metadata: found
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
};
|
|
142
|
+
// this logic is for autocomplete for moment
|
|
143
|
+
const findFieldInConfigForComponent = async (json, value) => {
|
|
144
|
+
if (json.formComponent && json.formComponent.type === 'AutoComplete') {
|
|
145
|
+
const url = json.formComponent.store.axios.url;
|
|
146
|
+
const method = json.formComponent.store.axios.method;
|
|
147
|
+
const data = json.formComponent.store.axios.data;
|
|
148
|
+
const idDD = json.formComponent.store.idDD;
|
|
149
|
+
const descDD = json.formComponent.store.descDD;
|
|
150
|
+
const config = {
|
|
151
|
+
method: method,
|
|
152
|
+
url: url,
|
|
153
|
+
headers: {
|
|
154
|
+
'Authorization': '' + process.env.TOKEN_PXP_ND + '',
|
|
155
|
+
'Content-Type': 'application/json'
|
|
156
|
+
},
|
|
157
|
+
data: {
|
|
158
|
+
...data,
|
|
159
|
+
[idDD]: value
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// @ts-ignore
|
|
163
|
+
const resControllerAxios = await core_1.__(axios_1.default(config));
|
|
164
|
+
const desc = resControllerAxios.data.data[descDD];
|
|
165
|
+
return desc;
|
|
166
|
+
}
|
|
167
|
+
else if (json.formComponentTemplate && json.configGetDescValue) { // todo we need to see how works here
|
|
168
|
+
const { controller, storeId, descColumn } = json.configGetDescValue;
|
|
169
|
+
const config = {
|
|
170
|
+
method: "get",
|
|
171
|
+
url: `http://localhost:${process.env.PORT}/api/${controller}`,
|
|
172
|
+
headers: {
|
|
173
|
+
'Authorization': '' + process.env.TOKEN_PXP_ND + '',
|
|
174
|
+
'Content-Type': 'application/json'
|
|
175
|
+
},
|
|
176
|
+
data: {
|
|
177
|
+
[storeId]: value
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
const resControllerAxios = await core_1.__(axios_1.default(config));
|
|
182
|
+
const desc = resControllerAxios.data.data[descColumn];
|
|
183
|
+
return desc;
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
};
|
|
187
|
+
for (const [nameKey, value] of Object.entries(mergeValues)) {
|
|
130
188
|
if (schemaJsonObject[nameKey]) {
|
|
189
|
+
const descValue = await core_1.__(findFieldInConfigForComponent(schemaJsonObject[nameKey], value));
|
|
131
190
|
schemaJsonObject[nameKey] = {
|
|
132
191
|
...schemaJsonObject[nameKey],
|
|
133
192
|
initialValue: value,
|
|
193
|
+
...(descValue && { descValue: descValue }),
|
|
134
194
|
...(verifyIfValueFromFieldMap(value) && { fromFieldMap: true, ...findFieldMapAndMetaData(value) }),
|
|
135
195
|
};
|
|
136
196
|
}
|
|
197
|
+
}
|
|
198
|
+
Object.entries(schemaJsonObject)
|
|
199
|
+
.filter(([, value]) => value.initialValue === undefined && value.fromFieldMap === undefined && value.fieldMappingType)
|
|
200
|
+
.forEach(([nameKey]) => {
|
|
201
|
+
const hasUniqueByTypeInMappingData = findFieldMapUniqueByType(schemaJsonObject[nameKey].fieldMappingType);
|
|
202
|
+
schemaJsonObject[nameKey] = {
|
|
203
|
+
...schemaJsonObject[nameKey],
|
|
204
|
+
...(hasUniqueByTypeInMappingData && { fromFieldMap: true, ...hasUniqueByTypeInMappingData }),
|
|
205
|
+
};
|
|
137
206
|
});
|
|
138
207
|
return {
|
|
139
208
|
actionConfigJsonObject,
|
package/dist/entity/Action.d.ts
CHANGED
package/dist/entity/Action.js
CHANGED
|
@@ -54,6 +54,10 @@ __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)
|
|
@@ -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()
|