rez_core 3.1.90 → 3.1.93
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/module/filter/service/filter.service.js +23 -71
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/mapper/controller/field-mapper.controller.d.ts +1 -1
- package/dist/module/mapper/service/field-mapper.service.d.ts +1 -1
- package/dist/module/mapper/service/field-mapper.service.js +2 -2
- package/dist/module/mapper/service/field-mapper.service.js.map +1 -1
- package/dist/module/workflow-automation/service/workflow-automation-engine.service.d.ts +1 -3
- package/dist/module/workflow-automation/service/workflow-automation-engine.service.js +32 -18
- package/dist/module/workflow-automation/service/workflow-automation-engine.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +100 -335
- package/src/module/mapper/service/field-mapper.service.ts +2 -2
- package/src/module/workflow-automation/service/workflow-automation-engine.service.ts +83 -74
|
@@ -92,7 +92,7 @@ export class FieldMapperService extends EntityServiceImpl {
|
|
|
92
92
|
const fieldMappers =
|
|
93
93
|
await this.fieldMapperRepository.findByMapperId(mapper_id);
|
|
94
94
|
|
|
95
|
-
const result
|
|
95
|
+
const result = new Map<string, any>();
|
|
96
96
|
const inMemory: Record<string, Record<string, any>> = {}; // cache for entity lookups
|
|
97
97
|
|
|
98
98
|
for (const field of fieldMappers) {
|
|
@@ -179,7 +179,7 @@ export class FieldMapperService extends EntityServiceImpl {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// Add to result
|
|
182
|
-
result
|
|
182
|
+
result.set(field.source_attribute, value);
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -4,7 +4,6 @@ import { WorkflowAutomationService } from './workflow-automation.service';
|
|
|
4
4
|
import { FilterEvaluatorService } from '../../filter/service/filter-evaluator.service';
|
|
5
5
|
import { Action } from '../interface/action.interface';
|
|
6
6
|
import { DataSource } from 'typeorm';
|
|
7
|
-
import { LoggingService } from 'src/utils/service/loggingUtil.service';
|
|
8
7
|
|
|
9
8
|
@Injectable()
|
|
10
9
|
export class WorkflowAutomationEngineService {
|
|
@@ -15,16 +14,12 @@ export class WorkflowAutomationEngineService {
|
|
|
15
14
|
private readonly wfService: WorkflowAutomationService,
|
|
16
15
|
private readonly filterEvaluator: FilterEvaluatorService,
|
|
17
16
|
private readonly dataSource: DataSource,
|
|
18
|
-
@Inject() protected readonly loggingService: LoggingService,
|
|
19
17
|
) {}
|
|
20
18
|
|
|
21
19
|
registerAction(actionName: string, actionInstance: Action) {
|
|
22
20
|
this.actions.set(actionName, actionInstance);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
'WorkflowAutomationEngine',
|
|
26
|
-
'registerAction',
|
|
27
|
-
`Registered action ${actionName}`,
|
|
21
|
+
console.log(
|
|
22
|
+
`⚙️ [WorkflowAutomationEngine] Registered action: ${actionName}`,
|
|
28
23
|
);
|
|
29
24
|
}
|
|
30
25
|
|
|
@@ -39,25 +34,40 @@ export class WorkflowAutomationEngineService {
|
|
|
39
34
|
user: any,
|
|
40
35
|
preUpdateStates?: Record<number, boolean> | null,
|
|
41
36
|
) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
'handleEntityEvent',
|
|
46
|
-
`Handling entity event: ${eventType} for entityType: ${entityType}`,
|
|
47
|
-
[newEntity?.id, preUpdateStates],
|
|
37
|
+
console.log(
|
|
38
|
+
`🟢 [WorkflowAutomationEngine] Handling entity event: ${eventType} for entityType: ${entityType}`,
|
|
39
|
+
{ entityId: newEntity?.id, preUpdateStates },
|
|
48
40
|
);
|
|
49
|
-
|
|
41
|
+
|
|
50
42
|
const workflows = await this.wfService.getActiveRules(
|
|
51
43
|
entityType,
|
|
52
44
|
eventType,
|
|
53
45
|
user,
|
|
54
46
|
);
|
|
55
|
-
|
|
47
|
+
|
|
48
|
+
console.log(
|
|
49
|
+
`📋 [WorkflowAutomationEngine] Found ${workflows.length} active workflows for entityType=${entityType}, eventType=${eventType}`,
|
|
50
|
+
);
|
|
51
|
+
|
|
56
52
|
for (const wf of workflows) {
|
|
53
|
+
console.log(
|
|
54
|
+
`\n🔹 [WorkflowAutomationEngine] Processing Workflow ID: ${wf.id}`,
|
|
55
|
+
{
|
|
56
|
+
workflow_name: wf.name,
|
|
57
|
+
applicable_entity_type: wf.applicable_entity_type,
|
|
58
|
+
mapped_entity_type: wf.mapped_entity_type,
|
|
59
|
+
condition_filter_code: wf.condition_filter_code,
|
|
60
|
+
criteria_filter_code: wf.criteria_filter_code,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
57
64
|
// Step 1️⃣ Condition / Trigger evaluation
|
|
58
65
|
let triggerMatched = false;
|
|
59
|
-
|
|
66
|
+
|
|
60
67
|
if (eventType === 'CREATE') {
|
|
68
|
+
console.log(
|
|
69
|
+
`➡️ [WorkflowAutomationEngine] Evaluating trigger (CREATE) for entity ${newEntity.id} using filter_code=${wf.condition_filter_code}`,
|
|
70
|
+
);
|
|
61
71
|
triggerMatched = await this.filterEvaluator.evaluateCriteria(
|
|
62
72
|
wf.applicable_entity_type,
|
|
63
73
|
wf.condition_filter_code,
|
|
@@ -66,6 +76,9 @@ export class WorkflowAutomationEngineService {
|
|
|
66
76
|
);
|
|
67
77
|
} else if (eventType === 'UPDATE' && preUpdateStates) {
|
|
68
78
|
const before = preUpdateStates[wf.id] ?? false;
|
|
79
|
+
console.log(
|
|
80
|
+
`➡️ [WorkflowAutomationEngine] Evaluating trigger (UPDATE) for entity ${newEntity.id} using filter_code=${wf.condition_filter_code}, previous=${before}`,
|
|
81
|
+
);
|
|
69
82
|
const after = await this.filterEvaluator.evaluateCriteria(
|
|
70
83
|
wf.applicable_entity_type,
|
|
71
84
|
wf.condition_filter_code,
|
|
@@ -73,48 +86,64 @@ export class WorkflowAutomationEngineService {
|
|
|
73
86
|
user,
|
|
74
87
|
);
|
|
75
88
|
triggerMatched = before !== after && after === true;
|
|
89
|
+
console.log(
|
|
90
|
+
`🔁 [WorkflowAutomationEngine] Trigger state changed: before=${before}, after=${after}, triggerMatched=${triggerMatched}`,
|
|
91
|
+
);
|
|
76
92
|
}
|
|
77
|
-
|
|
93
|
+
|
|
78
94
|
// 🔍 Log Step 1 result
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
'WorkflowAutomationEngine',
|
|
82
|
-
'handleEntityEvent',
|
|
83
|
-
`Step 1 - Trigger matched`,
|
|
84
|
-
[wf.id, triggerMatched],
|
|
95
|
+
console.log(
|
|
96
|
+
`🧩 [WorkflowAutomationEngine] Step 1 - Trigger matched for WF ${wf.id}: ${triggerMatched}`,
|
|
85
97
|
);
|
|
86
|
-
|
|
87
|
-
if (!triggerMatched)
|
|
88
|
-
|
|
98
|
+
|
|
99
|
+
if (!triggerMatched) {
|
|
100
|
+
console.log(
|
|
101
|
+
`⏩ [WorkflowAutomationEngine] Skipping workflow ${wf.id} as trigger did not match.`,
|
|
102
|
+
);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
// Step 2️⃣ Final criteria evaluation
|
|
90
|
-
|
|
91
107
|
const entityIdToUse =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
wf.mapped_entity_type === wf.applicable_entity_type
|
|
109
|
+
? newEntity.id
|
|
110
|
+
: newEntity.parent_id;
|
|
111
|
+
|
|
112
|
+
console.log(
|
|
113
|
+
`⚙️ [WorkflowAutomationEngine] Evaluating final criteria for mapped_entity_type=${wf.mapped_entity_type}, entityId=${entityIdToUse}, criteria_filter_code=${wf.criteria_filter_code}`,
|
|
114
|
+
);
|
|
115
|
+
|
|
96
116
|
const criteriaMatched = await this.filterEvaluator.evaluateCriteria(
|
|
97
117
|
wf.mapped_entity_type,
|
|
98
118
|
wf.criteria_filter_code,
|
|
99
119
|
entityIdToUse,
|
|
100
120
|
user,
|
|
101
121
|
);
|
|
102
|
-
|
|
122
|
+
|
|
103
123
|
// 🔍 Log Step 2 result
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
'WorkflowAutomationEngine',
|
|
107
|
-
'handleEntityEvent',
|
|
108
|
-
`Step 2 - Criteria matched`,
|
|
109
|
-
[wf.id, criteriaMatched],
|
|
124
|
+
console.log(
|
|
125
|
+
`⚖️ [WorkflowAutomationEngine] Step 2 - Criteria matched for WF ${wf.id}: ${criteriaMatched}`,
|
|
110
126
|
);
|
|
111
|
-
|
|
112
|
-
if (!criteriaMatched)
|
|
113
|
-
|
|
127
|
+
|
|
128
|
+
if (!criteriaMatched) {
|
|
129
|
+
console.log(
|
|
130
|
+
`⏩ [WorkflowAutomationEngine] Skipping workflow ${wf.id} as criteria did not match.`,
|
|
131
|
+
);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
114
135
|
// Step 3️⃣ Execute workflow actions
|
|
136
|
+
console.log(
|
|
137
|
+
`🚀 [WorkflowAutomationEngine] Executing actions for Workflow ID: ${wf.id}`,
|
|
138
|
+
);
|
|
115
139
|
await this.executeActions(wf.id, newEntity, user);
|
|
116
140
|
}
|
|
141
|
+
|
|
142
|
+
console.log(
|
|
143
|
+
`✅ [WorkflowAutomationEngine] Completed processing all workflows for ${entityType} (${eventType})`,
|
|
144
|
+
);
|
|
117
145
|
}
|
|
146
|
+
|
|
118
147
|
|
|
119
148
|
private async executeActions(
|
|
120
149
|
workflow_automation_id: number,
|
|
@@ -127,11 +156,8 @@ export class WorkflowAutomationEngineService {
|
|
|
127
156
|
);
|
|
128
157
|
|
|
129
158
|
if (!actions.length) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
'WorkflowAutomationEngine',
|
|
133
|
-
'executeActions',
|
|
134
|
-
`No actions found for workflow ${workflow_automation_id}`,
|
|
159
|
+
console.warn(
|
|
160
|
+
`⚠️ [WorkflowAutomationEngine] No actions found for workflow ${workflow_automation_id}`,
|
|
135
161
|
);
|
|
136
162
|
return;
|
|
137
163
|
}
|
|
@@ -145,11 +171,8 @@ export class WorkflowAutomationEngineService {
|
|
|
145
171
|
);
|
|
146
172
|
|
|
147
173
|
if (!category?.action_decorator) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
'WorkflowAutomationEngine',
|
|
151
|
-
'executeActions',
|
|
152
|
-
`No action_decorator found for category_id=${action.action_category_id}`,
|
|
174
|
+
console.warn(
|
|
175
|
+
`⚠️ [WorkflowAutomationEngine] No action_decorator found for category_id=${action.action_category_id}`,
|
|
153
176
|
);
|
|
154
177
|
continue;
|
|
155
178
|
}
|
|
@@ -160,21 +183,14 @@ export class WorkflowAutomationEngineService {
|
|
|
160
183
|
const impl = this.actions.get(decorator);
|
|
161
184
|
|
|
162
185
|
if (!impl) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
'WorkflowAutomationEngine',
|
|
166
|
-
'executeActions',
|
|
167
|
-
`No implementation found for action: ${decorator}`,
|
|
186
|
+
console.warn(
|
|
187
|
+
`⚠️ [WorkflowAutomationEngine] No implementation found for action: ${decorator}`,
|
|
168
188
|
);
|
|
169
189
|
continue;
|
|
170
190
|
}
|
|
171
191
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
'WorkflowAutomationEngine',
|
|
175
|
-
'executeActions',
|
|
176
|
-
`Executing action ${decorator} for entity ${entity.id}`,
|
|
177
|
-
[workflow_automation_id],
|
|
192
|
+
console.log(
|
|
193
|
+
`🚀 [WorkflowAutomationEngine] Executing action "${decorator}" for entity ${entity.id} (WF ${workflow_automation_id})`,
|
|
178
194
|
);
|
|
179
195
|
|
|
180
196
|
// 4️ Execute action with required context
|
|
@@ -184,20 +200,13 @@ export class WorkflowAutomationEngineService {
|
|
|
184
200
|
config: action.payload, // from cr_wf_action table
|
|
185
201
|
});
|
|
186
202
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
'WorkflowAutomationEngine',
|
|
190
|
-
'executeActions',
|
|
191
|
-
`Action ${decorator} executed successfully`,
|
|
192
|
-
[workflow_automation_id],
|
|
203
|
+
console.log(
|
|
204
|
+
`✅ [WorkflowAutomationEngine] Action "${decorator}" executed successfully (WF ${workflow_automation_id})`,
|
|
193
205
|
);
|
|
194
206
|
} catch (err) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
'executeActions',
|
|
199
|
-
`Error executing action (category_id=${action.action_category_id})`,
|
|
200
|
-
[err],
|
|
207
|
+
console.error(
|
|
208
|
+
`❌ [WorkflowAutomationEngine] Error executing action (category_id=${action.action_category_id}):`,
|
|
209
|
+
err,
|
|
201
210
|
);
|
|
202
211
|
}
|
|
203
212
|
}
|