251209:1453 Frontend: progress nest = UAT & Bug Fixing
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-09 14:53:42 +07:00
parent 8aceced902
commit aa96cd90e3
125 changed files with 11052 additions and 785 deletions

View File

@@ -0,0 +1,48 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { AuditLog } from '../../common/entities/audit-log.entity';
@Injectable()
export class AuditLogService {
constructor(
@InjectRepository(AuditLog)
private readonly auditLogRepository: Repository<AuditLog>
) {}
async findAll(query: any) {
const { page = 1, limit = 20, entityName, action, userId } = query;
const skip = (page - 1) * limit;
const queryBuilder =
this.auditLogRepository.createQueryBuilder('audit_logs'); // Aliased as 'audit_logs' matching table name usually, or just 'log'
if (entityName) {
queryBuilder.andWhere('audit_logs.entityName LIKE :entityName', {
entityName: `%${entityName}%`,
});
}
if (action) {
queryBuilder.andWhere('audit_logs.action = :action', { action });
}
if (userId) {
queryBuilder.andWhere('audit_logs.userId = :userId', { userId });
}
queryBuilder.orderBy('audit_logs.createdAt', 'DESC').skip(skip).take(limit);
const [data, total] = await queryBuilder.getManyAndCount();
return {
data,
meta: {
total,
page: Number(page),
limit: Number(limit),
totalPages: Math.ceil(total / limit),
},
};
}
}