feat(admin): add adminAlerts module shell with thresholds and signature helper

This commit is contained in:
Jennie Robinson Faber 2026-04-08 11:06:02 +01:00
parent 7544424484
commit d3a961f765
2 changed files with 125 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import { createHash } from 'node:crypto'
import Member from '../models/member.js'
import Event from '../models/event.js'
import PreRegistration from '../models/preRegistration.js'
import TagSuggestion from '../models/tagSuggestion.js'
import AdminAlertDismissal, { ADMIN_ALERT_TYPES } from '../models/adminAlertDismissal.js'
import { connectDB } from './mongoose.js'
export const ALERT_THRESHOLDS = {
NO_SLACK_DAYS: 7,
STUCK_PAYMENT_DAYS: 7,
PREREG_SELECTED_DAYS: 3,
DRAFT_IMMINENT_DAYS: 14,
NEAR_CAPACITY_RATIO: 0.8
}
const DAY_MS = 24 * 60 * 60 * 1000
function daysAgo(days) {
return new Date(Date.now() - days * DAY_MS)
}
function daysSince(date) {
if (!date) return null
return Math.floor((Date.now() - new Date(date).getTime()) / DAY_MS)
}
export function computeSignature(ids) {
const normalized = ids
.map((id) => (id == null ? '' : String(id)))
.sort()
const hash = createHash('sha1')
hash.update(JSON.stringify(normalized))
return hash.digest('hex')
}
// Alert functions land here in tasks 47.
// Aggregator lands in task 8.