Files
thebet365/apps/api/src/audit/audit.service.ts
Mars 14e49374ac 初始化足球投注平台 MVP Monorepo
包含 NestJS 后端、三端前端、Prisma 数据模型、结算引擎测试与 PRD 文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 14:35:48 +08:00

49 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class AuditService {
constructor(private prisma: PrismaService) {}
async log(data: {
operatorId?: bigint;
operatorType: string;
action: string;
module: string;
targetType?: string;
targetId?: string;
beforeData?: unknown;
afterData?: unknown;
ipAddress?: string;
}) {
return this.prisma.auditLog.create({
data: {
operatorId: data.operatorId,
operatorType: data.operatorType,
action: data.action,
module: data.module,
targetType: data.targetType,
targetId: data.targetId,
beforeData: data.beforeData ? JSON.stringify(data.beforeData) : null,
afterData: data.afterData ? JSON.stringify(data.afterData) : null,
ipAddress: data.ipAddress,
},
});
}
async list(page = 1, pageSize = 50, module?: string) {
const skip = (page - 1) * pageSize;
const where = module ? { module } : {};
const [items, total] = await Promise.all([
this.prisma.auditLog.findMany({
where,
orderBy: { createdAt: 'desc' },
skip,
take: pageSize,
}),
this.prisma.auditLog.count({ where }),
]);
return { items, total, page, pageSize };
}
}