Merge pull request 'feat: implement policy applicability and rule evaluation services for policy engine engine' (#31) from waseem into development
Reviewed-on: https://gitea.maskantech.in/gitea_admin/aeroresolve_backend/pulls/31
This commit is contained in:
@@ -51,6 +51,20 @@ export class PolicyApplicabilityService {
|
|||||||
const matchedCohortIds = new Set(matchedCohorts.map((c) => c.cohortId));
|
const matchedCohortIds = new Set(matchedCohorts.map((c) => c.cohortId));
|
||||||
|
|
||||||
const applicable = activePolicies.filter((policy) => {
|
const applicable = activePolicies.filter((policy) => {
|
||||||
|
// 0. Valid Rule & Condition Requirement Check
|
||||||
|
const rules = policy.rules || [];
|
||||||
|
const hasConfiguredConditions = rules.some((rule) => {
|
||||||
|
const conds = rule.conditions || [];
|
||||||
|
return conds.some((c) => Boolean(c.fieldId || (c as any).condition));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!hasConfiguredConditions) {
|
||||||
|
this.logger.warn(
|
||||||
|
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) contains no configured rule conditions or evaluation criteria.`,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Jurisdiction Match
|
// 1. Jurisdiction Match
|
||||||
const incidentJurisdiction = ctx.jurisdictionId || ctx.jurisdictionCode;
|
const incidentJurisdiction = ctx.jurisdictionId || ctx.jurisdictionCode;
|
||||||
const policyJurisdictions = policy.jurisdictions || [];
|
const policyJurisdictions = policy.jurisdictions || [];
|
||||||
|
|||||||
@@ -51,14 +51,16 @@ export class RuleEvaluationService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (sortedConditions.length === 0) {
|
if (sortedConditions.length === 0) {
|
||||||
this.logger.log(`>>> [RULE MATCHED ✅] Rule ID: ${rule.id} (Priority: ${rule.priority}) | Reason: No conditions defined (unconditional rule).`);
|
this.logger.warn(
|
||||||
|
`>>> [RULE NOT MATCHED ❌] Rule ID: ${rule.id} (Priority: ${rule.priority}) | Reason: No conditions configured for rule.`,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
ruleId: rule.id,
|
ruleId: rule.id,
|
||||||
category: rule.ruleCategoryId,
|
category: rule.ruleCategoryId,
|
||||||
priority: rule.priority || 1,
|
priority: rule.priority || 1,
|
||||||
matched: true,
|
matched: false,
|
||||||
conditions: [],
|
conditions: [],
|
||||||
reason: 'Unconditional rule automatically matched.',
|
reason: 'Rule has no configured conditions or evaluation criteria.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user