api-server/src/modules/active-recall/active-recall.repository.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Injectable } from '@nestjs/common';
import { generateShortId } from '../../common/utils/id.util';
export interface RecallQuestion {
id: string;
userId: string;
knowledgeItemId: string;
questionText: string;
difficulty: string;
}
export interface RecallAnswer {
id: string;
userId: string;
questionId: string;
answerText: string;
submittedAt: Date;
}
@Injectable()
export class ActiveRecallRepository {
private questions: Map<string, RecallQuestion> = new Map();
private answers: RecallAnswer[] = [];
async findByUserId(userId: string): Promise<RecallQuestion[]> {
return Array.from(this.questions.values()).filter((q) => q.userId === userId);
}
async findById(id: string): Promise<RecallQuestion | undefined> {
return this.questions.get(id);
}
async createQuestion(data: Partial<RecallQuestion>): Promise<RecallQuestion> {
const q: RecallQuestion = {
id: data.id || generateShortId(),
userId: data.userId || '',
knowledgeItemId: data.knowledgeItemId || '',
questionText: data.questionText || '',
difficulty: data.difficulty || 'normal',
};
this.questions.set(q.id, q);
return q;
}
async createAnswer(userId: string, questionId: string, body: any): Promise<RecallAnswer> {
const answer: RecallAnswer = {
id: generateShortId(),
userId,
questionId,
answerText: body.answerText || '',
submittedAt: new Date(),
};
this.answers.push(answer);
return answer;
}
}