45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
const mongoose = require('mongoose')
|
|
|
|
// تاریخچهی سیستم — هر عملِ نوشتاری (POST/PUT/PATCH/DELETE) که یه ادمین توی پنل انجام
|
|
// میده خودکار اینجا ثبت میشه (middlewares/auditLogger.js)، بدون نیاز به لاگ دستی
|
|
// توی تکتکِ کنترلرها
|
|
const AuditLogSchema = new mongoose.Schema(
|
|
{
|
|
adminId: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Admin',
|
|
required: true,
|
|
index: true
|
|
},
|
|
adminUserName: {
|
|
type: String,
|
|
default: null
|
|
},
|
|
method: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
path: {
|
|
type: String,
|
|
required: true,
|
|
index: true
|
|
},
|
|
statusCode: {
|
|
type: Number,
|
|
default: null
|
|
},
|
|
// خلاصهی بدنهی درخواست (پسورد/توکن حذف میشه) — برای اینکه معلوم باشه دقیقاً
|
|
// چه تغییری داده شده
|
|
body: {
|
|
type: mongoose.Schema.Types.Mixed,
|
|
default: null
|
|
}
|
|
},
|
|
{ timestamps: true }
|
|
)
|
|
|
|
AuditLogSchema.index({ createdAt: -1 })
|
|
AuditLogSchema.index({ adminId: 1, createdAt: -1 })
|
|
|
|
module.exports = mongoose.model('AuditLog', AuditLogSchema)
|