feat(admin): add adminAlerts module shell with thresholds and signature helper
This commit is contained in:
parent
7544424484
commit
d3a961f765
2 changed files with 125 additions and 0 deletions
39
server/utils/adminAlerts.js
Normal file
39
server/utils/adminAlerts.js
Normal 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 4–7.
|
||||
|
||||
// Aggregator lands in task 8.
|
||||
Loading…
Add table
Add a link
Reference in a new issue