重构 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,43 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../shared/prisma/prisma.service';
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
async findById(id: bigint) {
return this.prisma.user.findUnique({
where: { id },
include: { wallet: true, agentProfile: true, preferences: true },
});
}
async updateLocale(userId: bigint, locale: string) {
await this.prisma.user.update({
where: { id: userId },
data: { locale },
});
await this.prisma.userPreference.upsert({
where: { userId },
create: { userId, locale },
update: { locale },
});
return { locale };
}
async listPlayers(page = 1, pageSize = 20, parentId?: bigint) {
const where = { userType: 'PLAYER', ...(parentId ? { parentId } : {}) };
const skip = (page - 1) * pageSize;
const [items, total] = await Promise.all([
this.prisma.user.findMany({
where,
include: { wallet: true },
skip,
take: pageSize,
orderBy: { createdAt: 'desc' },
}),
this.prisma.user.count({ where }),
]);
return { items, total, page, pageSize };
}
}