- Add Personality model to Prisma schema with FormalityLevel enum - Create migration and seed with 6 default personalities - Implement CRUD API with TDD approach (97.67% coverage) * PersonalitiesService: findAll, findOne, findDefault, create, update, remove * PersonalitiesController: REST endpoints with auth guards * Comprehensive test coverage (21 passing tests) - Add Personality types to shared package - Create frontend components: * PersonalitySelector: dropdown for choosing personality * PersonalityPreview: preview personality style and system prompt * PersonalityForm: create/edit personalities with validation * Settings page: manage personalities with CRUD operations - Integrate with Ollama API: * Support personalityId in chat endpoint * Auto-inject system prompt from personality * Fall back to default personality if not specified - API client for frontend personality management All tests passing with 97.67% backend coverage (exceeds 85% requirement)
136 lines
3.6 KiB
TypeScript
136 lines
3.6 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { KnowledgeService } from "./knowledge.service";
|
|
import { CreateEntryDto, UpdateEntryDto, EntryQueryDto } 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 } from "./services/link-sync.service";
|
|
|
|
/**
|
|
* 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
|
|
) {}
|
|
|
|
/**
|
|
* 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,
|
|
};
|
|
}
|
|
}
|