This commit is contained in:
payacom
2026-09-13 21:32:36 +03:30
parent 90c5f94b57
commit c302aea177
49 changed files with 4063 additions and 920 deletions

44
models/AuditLogModel.js Normal file
View File

@@ -0,0 +1,44 @@
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)