api-server/src/modules/active-recall/active-recall.service.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

38 lines
1.3 KiB
TypeScript

import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { ActiveRecallRepository } from './active-recall.repository';
import { ActiveRecallAnalysisWorkflow } from '../ai/workflows/active-recall-analysis.workflow';
@Injectable()
export class ActiveRecallService {
private readonly logger = new Logger(ActiveRecallService.name);
constructor(
private readonly repository: ActiveRecallRepository,
private readonly analysisWorkflow: ActiveRecallAnalysisWorkflow,
) {}
async findByUserId(userId: string) {
return this.repository.findByUserId(userId);
}
async submit(userId: string, questionId: string, body: { answerText: string }) {
const question = await this.repository.findById(questionId);
if (!question) throw new NotFoundException('问题不存在');
const answer = await this.repository.createAnswer(userId, questionId, body);
this.analysisWorkflow.execute({
userId,
questionText: question.questionText,
knowledgeItemContent: '',
userAnswer: body.answerText,
}).then((result) => {
this.logger.log(`Analysis complete for answer ${answer.id}: score=${result.score}`);
}).catch((err) => {
this.logger.error(`Analysis failed for answer ${answer.id}: ${err.message}`);
});
return answer;
}
}