feat: complete cmpp platform phases 0-5
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TenantId } from '../common/tenant-id.decorator';
|
||||
import { AuditService, CreateOperationLogDto } from './audit.service';
|
||||
|
||||
@ApiTags('audit')
|
||||
@Controller('admin/operation-logs')
|
||||
export class AuditController {
|
||||
constructor(private readonly audit: AuditService) {}
|
||||
|
||||
@Get()
|
||||
list(@TenantId() tenantId?: string) {
|
||||
return this.audit.list(tenantId);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: CreateOperationLogDto) {
|
||||
return this.audit.create(body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AuditController } from './audit.controller';
|
||||
import { AuditService } from './audit.service';
|
||||
|
||||
@Module({
|
||||
controllers: [AuditController],
|
||||
providers: [AuditService],
|
||||
exports: [AuditService],
|
||||
})
|
||||
export class AuditModule {}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
export interface CreateOperationLogDto {
|
||||
tenantId?: string;
|
||||
userId?: string;
|
||||
action: string;
|
||||
resource: string;
|
||||
resourceId?: string;
|
||||
ipAddress?: string;
|
||||
userAgent?: string;
|
||||
detail?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class AuditService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
list(tenantId?: string) {
|
||||
return this.prisma.operationLog.findMany({
|
||||
where: tenantId ? { tenantId } : undefined,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 100,
|
||||
});
|
||||
}
|
||||
|
||||
create(data: CreateOperationLogDto) {
|
||||
const createData: Prisma.OperationLogUncheckedCreateInput = {
|
||||
tenantId: data.tenantId,
|
||||
userId: data.userId,
|
||||
action: data.action,
|
||||
resource: data.resource,
|
||||
resourceId: data.resourceId,
|
||||
ipAddress: data.ipAddress,
|
||||
userAgent: data.userAgent,
|
||||
detail: data.detail as Prisma.InputJsonValue | undefined,
|
||||
};
|
||||
return this.prisma.operationLog.create({ data: createData });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user