feat: implement PolicyApplicabilityService to evaluate policy eligibility based on jurisdiction and cohort matches

This commit is contained in:
azeeee05
2026-08-19 12:31:23 +05:30
parent 6c1a80587e
commit b8510d9902
@@ -56,6 +56,12 @@ export class PolicyApplicabilityService {
const policyJurisdictions = policy.jurisdictions || [];
if (policyJurisdictions.length > 0) {
const isGlobal = policyJurisdictions.some((pj) => {
const pJVal = (pj.jurisdiction?.value || pj.jurisdiction?.label || '').trim().toUpperCase();
return pJVal === 'GLOBAL';
});
if (!isGlobal) {
if (!incidentJurisdiction) {
this.logger.warn(
`[POLICY REJECTED ❌] Policy "${policy.policyName}" (ID: ${policy.id}) requires a jurisdiction, but incident context has no jurisdiction.`,
@@ -68,6 +74,7 @@ export class PolicyApplicabilityService {
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) &&
@@ -82,6 +89,7 @@ export class PolicyApplicabilityService {
return false;
}
}
}
// 2. Audience / Cohort Match
if (policy.audienceType === AudienceType.ALL) {