Tests, UX improvements.
This commit is contained in:
parent
4e6f5d36b8
commit
0ae18f495e
63 changed files with 1384 additions and 2330 deletions
71
server/utils/activityLog.js
Normal file
71
server/utils/activityLog.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import ActivityLog from '../models/activityLog.js'
|
||||
|
||||
export const ACTIVITY_TYPES = {
|
||||
MEMBER_JOINED: 'member_joined',
|
||||
EVENT_REGISTERED: 'event_registered',
|
||||
EVENT_CANCELLED: 'event_cancelled',
|
||||
EVENT_WAITLISTED: 'event_waitlisted',
|
||||
PEER_SUPPORT_ENABLED: 'peer_support_enabled',
|
||||
PEER_SUPPORT_DISABLED: 'peer_support_disabled',
|
||||
CIRCLE_CHANGED: 'circle_changed',
|
||||
CONTRIBUTION_CHANGED: 'contribution_changed',
|
||||
EMAIL_CHANGED: 'email_changed',
|
||||
PROFILE_UPDATED: 'profile_updated',
|
||||
SUBSCRIPTION_CREATED: 'subscription_created',
|
||||
SUBSCRIPTION_CANCELLED: 'subscription_cancelled',
|
||||
STATUS_CHANGED: 'status_changed',
|
||||
ROLE_CHANGED: 'role_changed',
|
||||
ADMIN_PROFILE_UPDATE: 'admin_profile_update',
|
||||
SLACK_INVITED: 'slack_invited',
|
||||
EMAIL_SENT: 'email_sent'
|
||||
}
|
||||
|
||||
export const ACTIVITY_TYPE_DEFAULTS = {
|
||||
member_joined: 'public',
|
||||
event_registered: 'public',
|
||||
event_cancelled: 'member',
|
||||
event_waitlisted: 'member',
|
||||
peer_support_enabled: 'public',
|
||||
peer_support_disabled: 'member',
|
||||
circle_changed: 'member',
|
||||
contribution_changed: 'member',
|
||||
email_changed: 'member',
|
||||
profile_updated: 'member',
|
||||
subscription_created: 'member',
|
||||
subscription_cancelled: 'member',
|
||||
status_changed: 'admin',
|
||||
role_changed: 'admin',
|
||||
admin_profile_update: 'admin',
|
||||
slack_invited: 'admin',
|
||||
email_sent: 'member'
|
||||
}
|
||||
|
||||
/**
|
||||
* Log an activity for a member. Fire-and-forget — catches errors
|
||||
* and logs to console without blocking the request.
|
||||
*
|
||||
* @param {string|ObjectId} memberId
|
||||
* @param {string} type - one of ACTIVITY_TYPES values
|
||||
* @param {object} [metadata={}]
|
||||
* @param {object} [options]
|
||||
* @param {string|ObjectId} [options.performedBy] - admin who initiated the action
|
||||
* @param {string} [options.visibility] - override default visibility
|
||||
* @param {Date} [options.timestamp] - override Date.now (for backfill)
|
||||
*/
|
||||
export async function logActivity(memberId, type, metadata = {}, options = {}) {
|
||||
try {
|
||||
const visibility = options.visibility || ACTIVITY_TYPE_DEFAULTS[type] || 'member'
|
||||
const doc = {
|
||||
member: memberId,
|
||||
type,
|
||||
visibility,
|
||||
metadata
|
||||
}
|
||||
if (options.performedBy) doc.performedBy = options.performedBy
|
||||
if (options.timestamp) doc.timestamp = options.timestamp
|
||||
|
||||
return await ActivityLog.create(doc)
|
||||
} catch (err) {
|
||||
console.error(`[activityLog] Failed to log ${type} for member ${memberId}:`, err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue