Files
kavehhn f04c797be6 Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
2026-08-09 04:18:08 +02:00

88 lines
1.5 KiB
JavaScript

// /components/activityLogs/activityLogModel.js
'use strict';
const mongoose = require('mongoose');
const ACTIVITY_ACTIONS = [
'create',
'update',
'delete',
'login',
'logout',
'enroll',
'attendance',
'upload',
'retry',
'other'
];
const activityLogSchema = new mongoose.Schema(
{
actor: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
default: null,
index: true
},
actorUsername: {
type: String,
default: null,
index: true
},
actorName: {
type: String,
default: null
},
action: {
type: String,
enum: ACTIVITY_ACTIONS,
required: true,
index: true
},
resource: {
type: String,
required: true,
index: true
},
resourceId: {
type: String,
default: null
},
method: {
type: String,
required: true
},
path: {
type: String,
required: true
},
statusCode: {
type: Number,
default: null
},
ip: {
type: String,
default: null
},
userAgent: {
type: String,
default: null
},
description: {
type: String,
default: ''
},
metadata: {
type: mongoose.Schema.Types.Mixed,
default: {}
}
},
{ timestamps: true }
);
activityLogSchema.index({ createdAt: -1 });
activityLogSchema.index({ action: 1, createdAt: -1 });
module.exports = mongoose.model('ActivityLog', activityLogSchema);
module.exports.ACTIVITY_ACTIONS = ACTIVITY_ACTIONS;