api-server/src/modules/learning-session/learning-session.service.ts
wangdl 38a8629e42
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 11s
feat: M8 学习信息收集系统完整实现
Phase 1-2: 设计文档 + 数据库 (ReadingEvent/MaterialReadingProgress/TemporaryReadingMaterial/LearningSession扩展/DailyLearningActivity扩展/LearningRecord)
Phase 3: 批量上报 + 校验去重 + ReadingEventProcessorService
Phase 4: 4表聚合管线 (LearningSession/MaterialReadingProgress/DailyLearningActivity/LearningRecord)
Phase 5: 查询接口 (progress/continue/summary/trend/heatmap/history/reprocess)
Phase 6: 权限校验 + session中断清理 + API文档

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 21:09:13 +08:00

38 lines
1.1 KiB
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { LearningSessionRepository } from './learning-session.repository';
@Injectable()
export class LearningSessionService {
constructor(private readonly repository: LearningSessionRepository) {}
async start(userId: string, dto: any) {
return this.repository.create(userId, dto);
}
async end(id: string) {
const session = await this.repository.end(id);
if (!session) throw new NotFoundException('会话不存在');
return session;
}
async findByUserId(userId: string, opts: { page?: number; limit?: number; status?: string; sort?: string }) {
return this.repository.findByUserId(userId, opts);
}
/** Upsert a session from a reading event (M8 aggregation). */
async upsertFromReadingEvent(data: {
userId: string;
clientSessionId: string;
materialId: string;
readingTargetType: string;
knowledgeBaseId?: string | null;
eventType: string;
activeSecondsDelta: number;
position?: any;
timestampMs: number;
startedAt: Date;
}) {
return this.repository.upsertByClientSession(data);
}
}