重构 API 为 8 领域 + 应用层架构

将后端模块拆分为 domains、applications、shared 三层,结算计算器移入 domain 纯函数目录,API 路径与测试保持不变。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 14:48:41 +08:00
parent 14e49374ac
commit 4c92157299
47 changed files with 169 additions and 138 deletions

View File

@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { AuditService } from './audit.service';
@Global()
@Module({
providers: [AuditService],
exports: [AuditService],
})
export class AuditModule {}

View File

@@ -0,0 +1,48 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../../shared/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 };
}
}