ghostguild-org/server/utils/adminAlerts.js

39 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.