feat(admin): add alert aggregator with dismissal filtering
This commit is contained in:
parent
0dc1b6ddbc
commit
4f7a11bcf3
2 changed files with 150 additions and 1 deletions
|
|
@ -257,4 +257,49 @@ export async function detectPendingTagSuggestions() {
|
|||
}
|
||||
}
|
||||
|
||||
// Aggregator lands in task 8.
|
||||
const DETECTORS = [
|
||||
detectSlackInviteFailed,
|
||||
detectNoSlackHandleAfterWeek,
|
||||
detectStuckPendingPayment,
|
||||
detectSuspendedMembers,
|
||||
detectPreRegistrantSelectedNotInvited,
|
||||
detectPreRegistrantExpired,
|
||||
detectDraftEventsImminent,
|
||||
detectEventsNearCapacity,
|
||||
detectPendingTagSuggestions
|
||||
]
|
||||
|
||||
function signatureForAlert(alert) {
|
||||
if (Array.isArray(alert.signatureIds)) {
|
||||
return computeSignature(alert.signatureIds)
|
||||
}
|
||||
return computeSignature(alert.items.map((item) => item.id))
|
||||
}
|
||||
|
||||
export async function computeAllAlerts(adminId) {
|
||||
await connectDB()
|
||||
|
||||
const [rawAlerts, dismissals] = await Promise.all([
|
||||
Promise.all(DETECTORS.map((fn) => fn())),
|
||||
AdminAlertDismissal.find({ adminId }).lean()
|
||||
])
|
||||
|
||||
const dismissedByType = new Map()
|
||||
for (const d of dismissals) {
|
||||
dismissedByType.set(d.alertType, d.signature)
|
||||
}
|
||||
|
||||
const result = []
|
||||
for (const alert of rawAlerts) {
|
||||
if (!alert.items || alert.items.length === 0) continue
|
||||
const signature = signatureForAlert(alert)
|
||||
if (dismissedByType.get(alert.type) === signature) continue
|
||||
const { signatureIds, ...publicFields } = alert
|
||||
result.push({
|
||||
...publicFields,
|
||||
count: alert.items.length,
|
||||
signature
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue