refactor: modularize notification job creation and enforce plan-based channel availability in policy resolver

This commit is contained in:
2026-07-27 22:51:33 -03:00
parent dc020d94d2
commit 68d98e8b40
6 changed files with 333 additions and 58 deletions
@@ -93,6 +93,21 @@ export class PolicyResolver {
};
}
async resolveAvailableChannels(
companyId: string,
channels: NotificationChannel[]
): Promise<NotificationChannel[]> {
const companyPolicy = await this.companyPolicyAdapter.findOne({ companyId });
const enabledChannels = companyPolicy
? companyPolicy.defaultChannels
: SYSTEM_DEFAULT_CHANNELS;
const companyEnabledChannels = channels.filter((channel) =>
enabledChannels.includes(channel)
);
return this.applyPlanLimits(companyId, companyEnabledChannels);
}
/**
* Returns muted channels from the winning cascade level only.
* Per spec, muted channels are NOT merged across levels.