feat: add domains, ideas, layouts, widgets API modules

- Add DomainsModule with full CRUD, search, and activity logging
- Add IdeasModule with quick capture endpoint
- Add LayoutsModule for user dashboard layouts
- Add WidgetsModule for widget definitions (read-only)
- Update ActivityService with domain/idea logging methods
- Register all new modules in AppModule
This commit is contained in:
Jason Woltje
2026-01-29 13:47:03 -06:00
parent 973502f26e
commit f47dd8bc92
66 changed files with 4277 additions and 29 deletions

View File

@@ -0,0 +1,22 @@
import {
IsString,
IsOptional,
MinLength,
MaxLength,
} from "class-validator";
/**
* DTO for quick capturing ideas with minimal fields
* Intended for rapid idea capture without complex categorization
*/
export class CaptureIdeaDto {
@IsString({ message: "content must be a string" })
@MinLength(1, { message: "content must not be empty" })
@MaxLength(50000, { message: "content must not exceed 50000 characters" })
content!: string;
@IsOptional()
@IsString({ message: "title must be a string" })
@MaxLength(500, { message: "title must not exceed 500 characters" })
title?: string;
}

View File

@@ -0,0 +1,56 @@
import { IdeaStatus, TaskPriority } from "@prisma/client";
import {
IsString,
IsOptional,
IsEnum,
IsArray,
IsUUID,
IsObject,
MinLength,
MaxLength,
} from "class-validator";
/**
* DTO for creating a new idea
*/
export class CreateIdeaDto {
@IsOptional()
@IsString({ message: "title must be a string" })
@MaxLength(500, { message: "title must not exceed 500 characters" })
title?: string;
@IsString({ message: "content must be a string" })
@MinLength(1, { message: "content must not be empty" })
@MaxLength(50000, { message: "content must not exceed 50000 characters" })
content!: string;
@IsOptional()
@IsUUID("4", { message: "domainId must be a valid UUID" })
domainId?: string;
@IsOptional()
@IsUUID("4", { message: "projectId must be a valid UUID" })
projectId?: string;
@IsOptional()
@IsEnum(IdeaStatus, { message: "status must be a valid IdeaStatus" })
status?: IdeaStatus;
@IsOptional()
@IsEnum(TaskPriority, { message: "priority must be a valid TaskPriority" })
priority?: TaskPriority;
@IsOptional()
@IsString({ message: "category must be a string" })
@MaxLength(100, { message: "category must not exceed 100 characters" })
category?: string;
@IsOptional()
@IsArray({ message: "tags must be an array" })
@IsString({ each: true, message: "each tag must be a string" })
tags?: string[];
@IsOptional()
@IsObject({ message: "metadata must be an object" })
metadata?: Record<string, unknown>;
}

View File

@@ -0,0 +1,4 @@
export { CreateIdeaDto } from "./create-idea.dto";
export { CaptureIdeaDto } from "./capture-idea.dto";
export { UpdateIdeaDto } from "./update-idea.dto";
export { QueryIdeasDto } from "./query-ideas.dto";

View File

@@ -0,0 +1,52 @@
import { IdeaStatus } from "@prisma/client";
import {
IsUUID,
IsOptional,
IsEnum,
IsInt,
Min,
Max,
IsString,
} from "class-validator";
import { Type } from "class-transformer";
/**
* DTO for querying ideas with filters and pagination
*/
export class QueryIdeasDto {
@IsUUID("4", { message: "workspaceId must be a valid UUID" })
workspaceId!: string;
@IsOptional()
@IsEnum(IdeaStatus, { message: "status must be a valid IdeaStatus" })
status?: IdeaStatus;
@IsOptional()
@IsUUID("4", { message: "domainId must be a valid UUID" })
domainId?: string;
@IsOptional()
@IsUUID("4", { message: "projectId must be a valid UUID" })
projectId?: string;
@IsOptional()
@IsString({ message: "category must be a string" })
category?: string;
@IsOptional()
@IsString({ message: "search must be a string" })
search?: string;
@IsOptional()
@Type(() => Number)
@IsInt({ message: "page must be an integer" })
@Min(1, { message: "page must be at least 1" })
page?: number;
@IsOptional()
@Type(() => Number)
@IsInt({ message: "limit must be an integer" })
@Min(1, { message: "limit must be at least 1" })
@Max(100, { message: "limit must not exceed 100" })
limit?: number;
}

View File

@@ -0,0 +1,58 @@
import { IdeaStatus, TaskPriority } from "@prisma/client";
import {
IsString,
IsOptional,
IsEnum,
IsArray,
IsUUID,
IsObject,
MinLength,
MaxLength,
} from "class-validator";
/**
* DTO for updating an existing idea
* All fields are optional to support partial updates
*/
export class UpdateIdeaDto {
@IsOptional()
@IsString({ message: "title must be a string" })
@MaxLength(500, { message: "title must not exceed 500 characters" })
title?: string;
@IsOptional()
@IsString({ message: "content must be a string" })
@MinLength(1, { message: "content must not be empty" })
@MaxLength(50000, { message: "content must not exceed 50000 characters" })
content?: string;
@IsOptional()
@IsUUID("4", { message: "domainId must be a valid UUID" })
domainId?: string;
@IsOptional()
@IsUUID("4", { message: "projectId must be a valid UUID" })
projectId?: string;
@IsOptional()
@IsEnum(IdeaStatus, { message: "status must be a valid IdeaStatus" })
status?: IdeaStatus;
@IsOptional()
@IsEnum(TaskPriority, { message: "priority must be a valid TaskPriority" })
priority?: TaskPriority;
@IsOptional()
@IsString({ message: "category must be a string" })
@MaxLength(100, { message: "category must not exceed 100 characters" })
category?: string;
@IsOptional()
@IsArray({ message: "tags must be an array" })
@IsString({ each: true, message: "each tag must be a string" })
tags?: string[];
@IsOptional()
@IsObject({ message: "metadata must be an object" })
metadata?: Record<string, unknown>;
}

View File

@@ -0,0 +1,130 @@
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
Query,
UseGuards,
Request,
UnauthorizedException,
} from "@nestjs/common";
import { IdeasService } from "./ideas.service";
import {
CreateIdeaDto,
CaptureIdeaDto,
UpdateIdeaDto,
QueryIdeasDto,
} from "./dto";
import { AuthGuard } from "../auth/guards/auth.guard";
/**
* Controller for idea endpoints
* All endpoints require authentication
*/
@Controller("ideas")
@UseGuards(AuthGuard)
export class IdeasController {
constructor(private readonly ideasService: IdeasService) {}
/**
* POST /api/ideas/capture
* Quick capture endpoint for rapid idea capture
* Requires minimal fields: content only (title optional)
*/
@Post("capture")
async capture(
@Body() captureIdeaDto: CaptureIdeaDto,
@Request() req: any
) {
const workspaceId = req.user?.workspaceId;
const userId = req.user?.id;
if (!workspaceId || !userId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.capture(workspaceId, userId, captureIdeaDto);
}
/**
* POST /api/ideas
* Create a new idea with full categorization options
*/
@Post()
async create(@Body() createIdeaDto: CreateIdeaDto, @Request() req: any) {
const workspaceId = req.user?.workspaceId;
const userId = req.user?.id;
if (!workspaceId || !userId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.create(workspaceId, userId, createIdeaDto);
}
/**
* GET /api/ideas
* Get paginated ideas with optional filters
* Supports status, domain, project, category, and search filters
*/
@Get()
async findAll(@Query() query: QueryIdeasDto, @Request() req: any) {
const workspaceId = req.user?.workspaceId;
if (!workspaceId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.findAll({ ...query, workspaceId });
}
/**
* GET /api/ideas/:id
* Get a single idea by ID
*/
@Get(":id")
async findOne(@Param("id") id: string, @Request() req: any) {
const workspaceId = req.user?.workspaceId;
if (!workspaceId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.findOne(id, workspaceId);
}
/**
* PATCH /api/ideas/:id
* Update an idea
*/
@Patch(":id")
async update(
@Param("id") id: string,
@Body() updateIdeaDto: UpdateIdeaDto,
@Request() req: any
) {
const workspaceId = req.user?.workspaceId;
const userId = req.user?.id;
if (!workspaceId || !userId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.update(id, workspaceId, userId, updateIdeaDto);
}
/**
* DELETE /api/ideas/:id
* Delete an idea
*/
@Delete(":id")
async remove(@Param("id") id: string, @Request() req: any) {
const workspaceId = req.user?.workspaceId;
const userId = req.user?.id;
if (!workspaceId || !userId) {
throw new UnauthorizedException("Authentication required");
}
return this.ideasService.remove(id, workspaceId, userId);
}
}

View File

@@ -0,0 +1,14 @@
import { Module } from "@nestjs/common";
import { IdeasController } from "./ideas.controller";
import { IdeasService } from "./ideas.service";
import { PrismaModule } from "../prisma/prisma.module";
import { ActivityModule } from "../activity/activity.module";
import { AuthModule } from "../auth/auth.module";
@Module({
imports: [PrismaModule, ActivityModule, AuthModule],
controllers: [IdeasController],
providers: [IdeasService],
exports: [IdeasService],
})
export class IdeasModule {}

View File

@@ -0,0 +1,293 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "../prisma/prisma.service";
import { ActivityService } from "../activity/activity.service";
import { IdeaStatus } from "@prisma/client";
import type {
CreateIdeaDto,
CaptureIdeaDto,
UpdateIdeaDto,
QueryIdeasDto,
} from "./dto";
/**
* Service for managing ideas
*/
@Injectable()
export class IdeasService {
constructor(
private readonly prisma: PrismaService,
private readonly activityService: ActivityService
) {}
/**
* Create a new idea
*/
async create(
workspaceId: string,
userId: string,
createIdeaDto: CreateIdeaDto
) {
const data: any = {
...createIdeaDto,
workspaceId,
creatorId: userId,
status: createIdeaDto.status || IdeaStatus.CAPTURED,
priority: createIdeaDto.priority || "MEDIUM",
tags: createIdeaDto.tags || [],
metadata: createIdeaDto.metadata || {},
};
const idea = await this.prisma.idea.create({
data,
include: {
creator: {
select: { id: true, name: true, email: true },
},
domain: {
select: { id: true, name: true, color: true },
},
project: {
select: { id: true, name: true, color: true },
},
},
});
// Log activity
await this.activityService.logIdeaCreated(
workspaceId,
userId,
idea.id,
{
title: idea.title || "Untitled",
}
);
return idea;
}
/**
* Quick capture - create an idea with minimal fields
* Optimized for rapid idea capture from the front-end
*/
async capture(
workspaceId: string,
userId: string,
captureIdeaDto: CaptureIdeaDto
) {
const data: any = {
workspaceId,
creatorId: userId,
content: captureIdeaDto.content,
title: captureIdeaDto.title,
status: IdeaStatus.CAPTURED,
priority: "MEDIUM",
tags: [],
metadata: {},
};
const idea = await this.prisma.idea.create({
data,
include: {
creator: {
select: { id: true, name: true, email: true },
},
},
});
// Log activity
await this.activityService.logIdeaCreated(
workspaceId,
userId,
idea.id,
{
quickCapture: true,
title: idea.title || "Untitled",
}
);
return idea;
}
/**
* Get paginated ideas with filters
*/
async findAll(query: QueryIdeasDto) {
const page = query.page || 1;
const limit = query.limit || 50;
const skip = (page - 1) * limit;
// Build where clause
const where: any = {
workspaceId: query.workspaceId,
};
if (query.status) {
where.status = query.status;
}
if (query.domainId) {
where.domainId = query.domainId;
}
if (query.projectId) {
where.projectId = query.projectId;
}
if (query.category) {
where.category = query.category;
}
// Add search filter if provided
if (query.search) {
where.OR = [
{ title: { contains: query.search, mode: "insensitive" } },
{ content: { contains: query.search, mode: "insensitive" } },
];
}
// Execute queries in parallel
const [data, total] = await Promise.all([
this.prisma.idea.findMany({
where,
include: {
creator: {
select: { id: true, name: true, email: true },
},
domain: {
select: { id: true, name: true, color: true },
},
project: {
select: { id: true, name: true, color: true },
},
},
orderBy: {
createdAt: "desc",
},
skip,
take: limit,
}),
this.prisma.idea.count({ where }),
]);
return {
data,
meta: {
total,
page,
limit,
totalPages: Math.ceil(total / limit),
},
};
}
/**
* Get a single idea by ID
*/
async findOne(id: string, workspaceId: string) {
const idea = await this.prisma.idea.findUnique({
where: {
id,
workspaceId,
},
include: {
creator: {
select: { id: true, name: true, email: true },
},
domain: {
select: { id: true, name: true, color: true },
},
project: {
select: { id: true, name: true, color: true },
},
},
});
if (!idea) {
throw new NotFoundException(`Idea with ID ${id} not found`);
}
return idea;
}
/**
* Update an idea
*/
async update(
id: string,
workspaceId: string,
userId: string,
updateIdeaDto: UpdateIdeaDto
) {
// Verify idea exists
const existingIdea = await this.prisma.idea.findUnique({
where: { id, workspaceId },
});
if (!existingIdea) {
throw new NotFoundException(`Idea with ID ${id} not found`);
}
const idea = await this.prisma.idea.update({
where: {
id,
workspaceId,
},
data: updateIdeaDto as any,
include: {
creator: {
select: { id: true, name: true, email: true },
},
domain: {
select: { id: true, name: true, color: true },
},
project: {
select: { id: true, name: true, color: true },
},
},
});
// Log activity
await this.activityService.logIdeaUpdated(
workspaceId,
userId,
id,
{
changes: updateIdeaDto as Prisma.JsonValue,
}
);
return idea;
}
/**
* Delete an idea
*/
async remove(id: string, workspaceId: string, userId: string) {
// Verify idea exists
const idea = await this.prisma.idea.findUnique({
where: { id, workspaceId },
});
if (!idea) {
throw new NotFoundException(`Idea with ID ${id} not found`);
}
await this.prisma.idea.delete({
where: {
id,
workspaceId,
},
});
// Log activity
await this.activityService.logIdeaDeleted(
workspaceId,
userId,
id,
{
title: idea.title || "Untitled",
}
);
}
}