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:
Syed Waseem khadri Rafai
2026-08-25 07:22:06 +00:00
2 changed files with 19 additions and 3 deletions
@@ -51,6 +51,20 @@ export class PolicyApplicabilityService {
const matchedCohortIds = new Set(matchedCohorts.map((c) => c.cohortId));
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
const incidentJurisdiction = ctx.jurisdictionId || ctx.jurisdictionCode;
const policyJurisdictions = policy.jurisdictions || [];
@@ -51,14 +51,16 @@ export class RuleEvaluationService {
);
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 {
ruleId: rule.id,
category: rule.ruleCategoryId,
priority: rule.priority || 1,
matched: true,
matched: false,
conditions: [],
reason: 'Unconditional rule automatically matched.',
reason: 'Rule has no configured conditions or evaluation criteria.',
};
}