Actualización módulo de authentication

This commit is contained in:
2026-07-02 19:44:30 +00:00
parent 7aaf12a6d0
commit 62a3beca15
7 changed files with 385 additions and 19 deletions

View File

@ -0,0 +1,110 @@
import auditLogModel from "./auditLog.model";
import { IAuditLog } from "./auditLog.interface";
export class AuditLogService {
//Registrar una acción
async create(
data:IAuditLog
){
const auditLog = new auditLogModel(data);
return await auditLog.save();
}
//Obtener todos los registros
async getAll(){
return await auditLogModel
.find()
.populate("userId")
.sort({
createdAt: -1
});
}
async getById(
id:string
){
return await auditLogModel
.findById(id)
.populate("userId");
}
async getByUser(
userId:string
){
return await auditLogModel
.find({
userId
})
.sort({
createdAt: -1
})
}
async getByModule(
module:IAuditLog["module"]
){
return await auditLogModel
.find({
module
})
.populate("userId")
.sort({
createdAt: -1
});
}
async getByAction(
action:IAuditLog["action"]
){
return await auditLogModel
.find({
action
})
.populate("userId")
.sort({
createdAt: -1
})
}
async getByStatus(
status:IAuditLog["status"]
){
return await auditLogModel
.find({
status
})
.populate("userId")
.sort({
createdAt: -1
})
}
async getByDateRange(
startDate:Date,
endDate:Date
){
return await auditLogModel
.find({
createdAt:{
$gte:startDate,
$lte:endDate
}
})
.populate("userId")
.sort({
createdAt: -1
})
}
async delete(
id:string
){
return await auditLogModel.findById(id);
}
}