4.1.3
This commit is contained in:
39
controllers/panel/auditLog/auditLogController.js
Normal file
39
controllers/panel/auditLog/auditLogController.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const AuditLog = require('../../../models/AuditLogModel')
|
||||
const AdminModel = require('../../../models/AdminModel')
|
||||
|
||||
const listAuditLog = async (req, res, next) => {
|
||||
try {
|
||||
const page = Math.max(parseInt(req.query.page, 10) || 1, 1)
|
||||
const limit = Math.min(parseInt(req.query.limit, 10) || 30, 100)
|
||||
const filter = {}
|
||||
if (req.query.adminId) filter.adminId = req.query.adminId
|
||||
|
||||
const [logs, total] = await Promise.all([
|
||||
AuditLog.find(filter)
|
||||
.sort({ createdAt: -1 })
|
||||
.skip((page - 1) * limit)
|
||||
.limit(limit)
|
||||
.lean(),
|
||||
AuditLog.countDocuments(filter)
|
||||
])
|
||||
|
||||
res.status(200).json({
|
||||
logs,
|
||||
totalPages: Math.ceil(total / limit) || 1,
|
||||
totalItems: total
|
||||
})
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
const listAdminsForFilter = async (req, res, next) => {
|
||||
try {
|
||||
const admins = await AdminModel.find({}).select('user_name first_name last_name').lean()
|
||||
res.status(200).json({ admins })
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { listAuditLog, listAdminsForFilter }
|
||||
Reference in New Issue
Block a user