fix: add missing /api/admin/learning/knowledge-bases endpoint
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 45s

Dashboard filter dropdown calls this to populate KB selector.
Returns knowledge bases that have reading event data with real titles.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-18 18:40:40 +08:00
parent c0a8f7ef27
commit c3fd6a221f
2 changed files with 26 additions and 0 deletions

View File

@ -16,6 +16,10 @@ export class AdminLearningController {
@Query('endDate') endDate?: string,
) { return this.service.getDashboard({ knowledgeBaseId, startDate, endDate }); }
// ── Knowledge Bases ──
@Get('knowledge-bases')
async getKnowledgeBases() { return this.service.getKnowledgeBases(); }
// ── ReadingEvents ──
@Get('reading-events')
async getReadingEvents(@Query() query: EventFilterQuery) { return this.service.getReadingEvents(query); }

View File

@ -9,6 +9,28 @@ export class AdminLearningService {
private readonly snapshotBuilder: SnapshotBuilderService,
) {}
// ══ Knowledge Bases (for filter dropdown) ══
async getKnowledgeBases() {
// Return knowledge bases that appear in reading_events, with real names from KB table
const ids = await this.prisma.readingEvent.findMany({
where: { knowledgeBaseId: { not: null } },
select: { knowledgeBaseId: true },
distinct: ['knowledgeBaseId'],
take: 200,
});
const kbIds = [...new Set(ids.map(r => r.knowledgeBaseId!).filter(Boolean))];
if (kbIds.length === 0) return [];
const kbs = await this.prisma.knowledgeBase.findMany({
where: { id: { in: kbIds } },
select: { id: true, title: true },
take: 200,
});
return kbs.map(kb => ({ id: kb.id, name: kb.title }));
}
// ══ Dashboard ══
async getDashboard(filters?: { knowledgeBaseId?: string; startDate?: string; endDate?: string }) {