feature/IO-3096-GlobalNotifications - Check-point

This commit is contained in:
Dave Richer
2025-02-10 17:15:53 -05:00
parent b1ffbe0e12
commit 54820fe3c8
6 changed files with 72 additions and 11 deletions

View File

@@ -62,11 +62,27 @@ const scenarioParser = async (req) => {
if (isEmpty(associationsData?.associations)) return;
// Step 6: For each matching scenario, add a scenarioWatchers property
// that includes only the jobWatchers with the notification setting enabled
// that includes only the jobWatchers with at least one notification method enabled.
// Each watcher object is formatted as: { user, email, app, fcm }
finalScenarioData.matchingScenarios.forEach((scenario) => {
scenario.scenarioWatchers = associationsData.associations
.filter((assoc) => assoc.notification_settings && assoc.notification_settings[scenario.key] === true)
.map((assoc) => assoc.useremail);
.filter((assoc) => {
// Retrieve the settings object for this scenario (it now contains app, email, and fcm)
const settings = assoc.notification_settings && assoc.notification_settings[scenario.key];
// Only include this association if at least one notification channel is enabled
return settings && (settings.app || settings.email || settings.fcm);
})
.map((assoc) => {
const settings = assoc.notification_settings[scenario.key];
return {
// Use assoc.user if available, otherwise fallback to assoc.useremail as the identifier
user: assoc.user || assoc.useremail,
// The email field here is the user's email notification setting (boolean)
email: settings.email,
app: settings.app,
fcm: settings.fcm
};
});
});
// Step 7: Call builder functions for each matching scenario (fire-and-forget)