2026-05-09 18:25:04 +08:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2026-05-17 00:39:46 +08:00
|
|
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
2026-05-09 18:25:04 +08:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ActiveRecallRepository {
|
2026-05-17 00:39:46 +08:00
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
2026-05-09 18:25:04 +08:00
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async findByUserId(userId: string) {
|
|
|
|
|
return this.prisma.activeRecallQuestion.findMany({
|
|
|
|
|
where: { userId },
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async findById(id: string) {
|
|
|
|
|
return this.prisma.activeRecallQuestion.findUnique({ where: { id } });
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async createQuestion(data: {
|
|
|
|
|
userId: string;
|
|
|
|
|
knowledgeItemId?: string;
|
|
|
|
|
questionText: string;
|
|
|
|
|
difficulty?: string;
|
|
|
|
|
createdBy?: string;
|
|
|
|
|
}) {
|
|
|
|
|
return this.prisma.activeRecallQuestion.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: data.userId,
|
|
|
|
|
knowledgeItemId: data.knowledgeItemId ?? null,
|
|
|
|
|
questionText: data.questionText,
|
|
|
|
|
difficulty: data.difficulty ?? 'normal',
|
|
|
|
|
createdBy: data.createdBy ?? 'ai',
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async createAnswer(userId: string, questionId: string, body: { answerText: string }) {
|
|
|
|
|
return this.prisma.activeRecallAnswer.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId,
|
|
|
|
|
questionId,
|
|
|
|
|
answerText: body.answerText,
|
|
|
|
|
submittedAt: new Date(),
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
}
|