Merge pull request 'feat: implement PolicyApplicabilityService to evaluate policy eligibility based on jurisdiction and cohort matches' (#28) from azeem into development
Reviewed-on: https://gitea.maskantech.in/gitea_admin/aeroresolve_backend/pulls/28
This commit is contained in:
@@ -56,30 +56,38 @@ export class PolicyApplicabilityService {
|
||||
const policyJurisdictions = policy.jurisdictions || [];
|
||||
|
||||
if (policyJurisdictions.length > 0) {
|
||||
if (!incidentJurisdiction) {
|
||||
this.logger.warn(
|
||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) requires a jurisdiction, but incident context has no jurisdiction.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const incJVal = incidentJurisdiction.trim().toUpperCase();
|
||||
|
||||
const hasMatch = policyJurisdictions.some((pj) => {
|
||||
const pJId = pj.jurisdictionId;
|
||||
const isGlobal = policyJurisdictions.some((pj) => {
|
||||
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
|
||||
const matchesId = Boolean(pJId) && pJId === incidentJurisdiction;
|
||||
const matchesVal =
|
||||
Boolean(pJVal) &&
|
||||
(pJVal === incJVal || pJVal.includes(incJVal) || incJVal.includes(pJVal));
|
||||
return matchesId || matchesVal;
|
||||
return pJVal === 'GLOBAL';
|
||||
});
|
||||
|
||||
if (!hasMatch) {
|
||||
this.logger.warn(
|
||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) jurisdictions DO NOT MATCH incident jurisdiction ("${incJVal}").`,
|
||||
);
|
||||
return false;
|
||||
if (!isGlobal) {
|
||||
if (!incidentJurisdiction) {
|
||||
this.logger.warn(
|
||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) requires a jurisdiction, but incident context has no jurisdiction.`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
const incJVal = incidentJurisdiction.trim().toUpperCase();
|
||||
|
||||
const hasMatch = policyJurisdictions.some((pj) => {
|
||||
const pJId = pj.jurisdictionId;
|
||||
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
|
||||
|
||||
const matchesId = Boolean(pJId) && pJId === incidentJurisdiction;
|
||||
const matchesVal =
|
||||
Boolean(pJVal) &&
|
||||
(pJVal === incJVal || pJVal.includes(incJVal) || incJVal.includes(pJVal));
|
||||
return matchesId || matchesVal;
|
||||
});
|
||||
|
||||
if (!hasMatch) {
|
||||
this.logger.warn(
|
||||
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) jurisdictions DO NOT MATCH incident jurisdiction ("${incJVal}").`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user