Schema additions for issues #37-41: New models: - Domain (#37): Life domains (work, marriage, homelab, etc.) - Idea (#38): Brain dumps with pgvector embeddings - Relationship (#39): Generic entity linking (blocks, depends_on) - Agent (#40): ClawdBot agent tracking with metrics - AgentSession (#40): Conversation session tracking - WidgetDefinition (#41): HUD widget registry - UserLayout (#41): Per-user dashboard configuration Updated models: - Task, Event, Project: Added domainId foreign key - User, Workspace: Added new relations New enums: - IdeaStatus: CAPTURED, PROCESSING, ACTIONABLE, ARCHIVED, DISCARDED - RelationshipType: BLOCKS, BLOCKED_BY, DEPENDS_ON, etc. - AgentStatus: IDLE, WORKING, WAITING, ERROR, TERMINATED - EntityType: Added IDEA, DOMAIN Migration: 20260129182803_add_domains_ideas_agents_widgets
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { Controller, Get, Query, Param, UseGuards, Request } from "@nestjs/common";
|
|
import { ActivityService } from "./activity.service";
|
|
import { EntityType } from "@prisma/client";
|
|
import type { QueryActivityLogDto } from "./dto";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
|
|
/**
|
|
* Controller for activity log endpoints
|
|
* All endpoints require authentication
|
|
*/
|
|
@Controller("activity")
|
|
@UseGuards(AuthGuard)
|
|
export class ActivityController {
|
|
constructor(private readonly activityService: ActivityService) {}
|
|
|
|
/**
|
|
* GET /api/activity
|
|
* Get paginated activity logs with optional filters
|
|
* workspaceId is extracted from authenticated user context
|
|
*/
|
|
@Get()
|
|
async findAll(@Query() query: QueryActivityLogDto, @Request() req: any) {
|
|
// Extract workspaceId from authenticated user
|
|
const workspaceId = req.user?.workspaceId || query.workspaceId;
|
|
return this.activityService.findAll({ ...query, workspaceId });
|
|
}
|
|
|
|
/**
|
|
* GET /api/activity/:id
|
|
* Get a single activity log by ID
|
|
* workspaceId is extracted from authenticated user context
|
|
*/
|
|
@Get(":id")
|
|
async findOne(@Param("id") id: string, @Request() req: any) {
|
|
const workspaceId = req.user?.workspaceId;
|
|
if (!workspaceId) {
|
|
throw new Error("User workspaceId not found");
|
|
}
|
|
return this.activityService.findOne(id, workspaceId);
|
|
}
|
|
|
|
/**
|
|
* GET /api/activity/audit/:entityType/:entityId
|
|
* Get audit trail for a specific entity
|
|
* workspaceId is extracted from authenticated user context
|
|
*/
|
|
@Get("audit/:entityType/:entityId")
|
|
async getAuditTrail(
|
|
@Request() req: any,
|
|
@Param("entityType") entityType: EntityType,
|
|
@Param("entityId") entityId: string
|
|
) {
|
|
const workspaceId = req.user?.workspaceId;
|
|
if (!workspaceId) {
|
|
throw new Error("User workspaceId not found");
|
|
}
|
|
return this.activityService.getAuditTrail(workspaceId, entityType, entityId);
|
|
}
|
|
}
|