Actualización módulo de authentication
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user