Issue #73 - Entry-Centered Graph View: - Added GET /api/knowledge/entries/:id/graph endpoint with depth parameter - Returns entry + connected nodes with link relationships - Created GraphService for graph traversal using BFS - Added EntryGraphViewer component for frontend - Integrated graph view tab into entry detail page Issue #74 - Graph Statistics Dashboard: - Added GET /api/knowledge/stats endpoint - Returns overview stats (entries, tags, links by status) - Includes most connected entries, recent activity, tag distribution - Created StatsDashboard component with visual stats - Added route at /knowledge/stats Backend: - GraphService: BFS-based graph traversal with configurable depth - StatsService: Parallel queries for comprehensive statistics - GraphQueryDto: Validation for depth parameter (1-5) - Entity types for graph nodes/edges and statistics - Unit tests for both services Frontend: - EntryGraphViewer: Entry-centered graph visualization - StatsDashboard: Statistics overview with charts - Graph view tab on entry detail page - API client functions for new endpoints - TypeScript strict typing throughout
164 lines
4.3 KiB
TypeScript
164 lines
4.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { KnowledgeService } from "./knowledge.service";
|
|
import { CreateEntryDto, UpdateEntryDto, EntryQueryDto, GraphQueryDto } from "./dto";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
import { WorkspaceGuard, PermissionGuard } from "../common/guards";
|
|
import { Workspace, Permission, RequirePermission } from "../common/decorators";
|
|
import { CurrentUser } from "../auth/decorators/current-user.decorator";
|
|
import { LinkSyncService, GraphService } from "./services";
|
|
|
|
/**
|
|
* Controller for knowledge entry endpoints
|
|
* All endpoints require authentication and workspace context
|
|
* Uses the new guard-based permission system
|
|
*/
|
|
@Controller("knowledge/entries")
|
|
@UseGuards(AuthGuard, WorkspaceGuard, PermissionGuard)
|
|
export class KnowledgeController {
|
|
constructor(
|
|
private readonly knowledgeService: KnowledgeService,
|
|
private readonly linkSync: LinkSyncService,
|
|
private readonly graphService: GraphService
|
|
) {}
|
|
|
|
/**
|
|
* GET /api/knowledge/entries
|
|
* List all entries in the workspace with pagination and filtering
|
|
* Requires: Any workspace member
|
|
*/
|
|
@Get()
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async findAll(
|
|
@Workspace() workspaceId: string,
|
|
@Query() query: EntryQueryDto
|
|
) {
|
|
return this.knowledgeService.findAll(workspaceId, query);
|
|
}
|
|
|
|
/**
|
|
* GET /api/knowledge/entries/:slug
|
|
* Get a single entry by slug
|
|
* Requires: Any workspace member
|
|
*/
|
|
@Get(":slug")
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async findOne(
|
|
@Workspace() workspaceId: string,
|
|
@Param("slug") slug: string
|
|
) {
|
|
return this.knowledgeService.findOne(workspaceId, slug);
|
|
}
|
|
|
|
/**
|
|
* POST /api/knowledge/entries
|
|
* Create a new knowledge entry
|
|
* Requires: MEMBER role or higher
|
|
*/
|
|
@Post()
|
|
@RequirePermission(Permission.WORKSPACE_MEMBER)
|
|
async create(
|
|
@Workspace() workspaceId: string,
|
|
@CurrentUser() user: any,
|
|
@Body() createDto: CreateEntryDto
|
|
) {
|
|
return this.knowledgeService.create(workspaceId, user.id, createDto);
|
|
}
|
|
|
|
/**
|
|
* PUT /api/knowledge/entries/:slug
|
|
* Update an existing entry
|
|
* Requires: MEMBER role or higher
|
|
*/
|
|
@Put(":slug")
|
|
@RequirePermission(Permission.WORKSPACE_MEMBER)
|
|
async update(
|
|
@Workspace() workspaceId: string,
|
|
@Param("slug") slug: string,
|
|
@CurrentUser() user: any,
|
|
@Body() updateDto: UpdateEntryDto
|
|
) {
|
|
return this.knowledgeService.update(workspaceId, slug, user.id, updateDto);
|
|
}
|
|
|
|
/**
|
|
* DELETE /api/knowledge/entries/:slug
|
|
* Soft delete an entry (sets status to ARCHIVED)
|
|
* Requires: ADMIN role or higher
|
|
*/
|
|
@Delete(":slug")
|
|
@RequirePermission(Permission.WORKSPACE_ADMIN)
|
|
async remove(
|
|
@Workspace() workspaceId: string,
|
|
@Param("slug") slug: string,
|
|
@CurrentUser() user: any
|
|
) {
|
|
await this.knowledgeService.remove(workspaceId, slug, user.id);
|
|
return { message: "Entry archived successfully" };
|
|
}
|
|
|
|
/**
|
|
* GET /api/knowledge/entries/:slug/backlinks
|
|
* Get all backlinks for an entry
|
|
* Requires: Any workspace member
|
|
*/
|
|
@Get(":slug/backlinks")
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async getBacklinks(
|
|
@Workspace() workspaceId: string,
|
|
@Param("slug") slug: string
|
|
) {
|
|
// First find the entry to get its ID
|
|
const entry = await this.knowledgeService.findOne(workspaceId, slug);
|
|
|
|
// Get backlinks
|
|
const backlinks = await this.linkSync.getBacklinks(entry.id);
|
|
|
|
return {
|
|
entry: {
|
|
id: entry.id,
|
|
slug: entry.slug,
|
|
title: entry.title,
|
|
},
|
|
backlinks,
|
|
count: backlinks.length,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* GET /api/knowledge/entries/:slug/graph
|
|
* Get entry-centered graph view
|
|
* Returns the entry and connected nodes with specified depth
|
|
* Requires: Any workspace member
|
|
*/
|
|
@Get(":slug/graph")
|
|
@RequirePermission(Permission.WORKSPACE_ANY)
|
|
async getEntryGraph(
|
|
@Workspace() workspaceId: string,
|
|
@Param("slug") slug: string,
|
|
@Query() query: GraphQueryDto
|
|
) {
|
|
// Find the entry to get its ID
|
|
const entry = await this.knowledgeService.findOne(workspaceId, slug);
|
|
|
|
// Get graph
|
|
const graph = await this.graphService.getEntryGraph(
|
|
workspaceId,
|
|
entry.id,
|
|
query.depth || 1
|
|
);
|
|
|
|
return graph;
|
|
}
|
|
|
|
}
|