251209:1453 Frontend: progress nest = UAT & Bug Fixing
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
||||
import { AuditLogService } from './audit-log.service';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { RbacGuard } from '../../common/guards/rbac.guard';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
|
||||
@Controller('audit-logs')
|
||||
@UseGuards(JwtAuthGuard, RbacGuard)
|
||||
export class AuditLogController {
|
||||
constructor(private readonly auditLogService: AuditLogService) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('audit-log.view')
|
||||
findAll(@Query() query: any) {
|
||||
return this.auditLogService.findAll(query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AuditLogController } from './audit-log.controller';
|
||||
import { AuditLogService } from './audit-log.service';
|
||||
import { AuditLog } from '../../common/entities/audit-log.entity';
|
||||
import { UserModule } from '../user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([AuditLog]), UserModule],
|
||||
controllers: [AuditLogController],
|
||||
providers: [AuditLogService],
|
||||
exports: [AuditLogService],
|
||||
})
|
||||
export class AuditLogModule {}
|
||||
@@ -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),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user