api-server/src/modules/users/users.repository.ts
WangDL 007b56dad5
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 1m0s
feat: AI三层架构 + 全局JwtAuthGuard + 12个Repository迁Prisma
- AI: 新三层架构 Provider→Gateway→Workflow(15文件,DeepSeek+MiniMax)
- Auth: 全局JwtAuthGuard + @Public()装饰器白名单路由
- DB: 12个Repository从Map/Array迁到Prisma
- Schema: 新增AiUsageLog、WaitlistEntry模型
- API: /api-docs-json加Basic Auth保护
- 清理: 删除infrastructure/ai、docs/旧文档

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-17 00:39:46 +08:00

64 lines
1.6 KiB
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../infrastructure/database/prisma.service';
@Injectable()
export class UsersRepository {
constructor(private readonly prisma: PrismaService) {}
async findProfileByUserId(userId: string) {
const user = await this.prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
email: true,
nickname: true,
avatarUrl: true,
role: true,
status: true,
onboardingCompleted: true,
createdAt: true,
},
});
if (!user) {
throw new NotFoundException('用户不存在');
}
return {
id: user.id,
email: user.email,
nickname: user.nickname,
avatarUrl: user.avatarUrl,
role: user.role,
status: user.status,
onboardingCompleted: user.onboardingCompleted,
createdAt: user.createdAt,
};
}
async updateProfile(userId: string, dto: any) {
return this.prisma.user.update({
where: { id: userId },
data: {
nickname: dto.nickname,
avatarUrl: dto.avatarUrl,
},
});
}
async updatePreferences(userId: string, dto: any) {
return this.prisma.userPreference.upsert({
where: { userId },
create: {
userId,
defaultFocusMinutes: dto.defaultFocusMinutes ?? 25,
aiSuggestionLevel: dto.aiSuggestionLevel ?? 'normal',
language: dto.language ?? 'zh-CN',
appearance: dto.appearance ?? 'system',
notificationEnabled: dto.notificationEnabled ?? true,
},
update: dto,
});
}
}