feat(#5): Implement CRUD APIs for tasks, events, and projects
Implements comprehensive CRUD APIs following TDD principles with 92.44% test coverage (exceeds 85% requirement). Features: - Tasks API: Full CRUD with filtering, pagination, and subtask support - Events API: Full CRUD with recurrence support and date filtering - Projects API: Full CRUD with task/event association - Authentication guards on all endpoints - Workspace-scoped queries for multi-tenant isolation - Activity logging for all operations (CREATED, UPDATED, DELETED, etc.) - DTOs with class-validator validation - Comprehensive test suite (221 tests, 44 for new APIs) Implementation: - Services: Business logic with Prisma ORM integration - Controllers: RESTful endpoints with AuthGuard - Modules: Properly registered in AppModule - Documentation: Complete API reference in docs/4-api/4-crud-endpoints/ Test Coverage: - Tasks: 96.1% - Events: 89.83% - Projects: 84.21% - Overall: 92.44% TDD Workflow: 1. RED: Wrote failing tests first 2. GREEN: Implemented minimal code to pass tests 3. REFACTOR: Improved code quality while maintaining coverage Refs #5 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
53
apps/api/src/events/dto/create-event.dto.ts
Normal file
53
apps/api/src/events/dto/create-event.dto.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
IsString,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
IsDateString,
|
||||
IsBoolean,
|
||||
IsObject,
|
||||
MinLength,
|
||||
MaxLength,
|
||||
} from "class-validator";
|
||||
|
||||
/**
|
||||
* DTO for creating a new event
|
||||
*/
|
||||
export class CreateEventDto {
|
||||
@IsString({ message: "title must be a string" })
|
||||
@MinLength(1, { message: "title must not be empty" })
|
||||
@MaxLength(255, { message: "title must not exceed 255 characters" })
|
||||
title!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString({ message: "description must be a string" })
|
||||
@MaxLength(10000, { message: "description must not exceed 10000 characters" })
|
||||
description?: string;
|
||||
|
||||
@IsDateString({}, { message: "startTime must be a valid ISO 8601 date string" })
|
||||
startTime!: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString({}, { message: "endTime must be a valid ISO 8601 date string" })
|
||||
endTime?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean({ message: "allDay must be a boolean" })
|
||||
allDay?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString({ message: "location must be a string" })
|
||||
@MaxLength(500, { message: "location must not exceed 500 characters" })
|
||||
location?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject({ message: "recurrence must be an object" })
|
||||
recurrence?: Record<string, unknown>;
|
||||
|
||||
@IsOptional()
|
||||
@IsUUID("4", { message: "projectId must be a valid UUID" })
|
||||
projectId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject({ message: "metadata must be an object" })
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
3
apps/api/src/events/dto/index.ts
Normal file
3
apps/api/src/events/dto/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { CreateEventDto } from "./create-event.dto";
|
||||
export { UpdateEventDto } from "./update-event.dto";
|
||||
export { QueryEventsDto } from "./query-events.dto";
|
||||
48
apps/api/src/events/dto/query-events.dto.ts
Normal file
48
apps/api/src/events/dto/query-events.dto.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
IsUUID,
|
||||
IsOptional,
|
||||
IsInt,
|
||||
Min,
|
||||
Max,
|
||||
IsDateString,
|
||||
IsBoolean,
|
||||
} from "class-validator";
|
||||
import { Type } from "class-transformer";
|
||||
|
||||
/**
|
||||
* DTO for querying events with filters and pagination
|
||||
*/
|
||||
export class QueryEventsDto {
|
||||
@IsUUID("4", { message: "workspaceId must be a valid UUID" })
|
||||
workspaceId!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsUUID("4", { message: "projectId must be a valid UUID" })
|
||||
projectId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString({}, { message: "startFrom must be a valid ISO 8601 date string" })
|
||||
startFrom?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString({}, { message: "startTo must be a valid ISO 8601 date string" })
|
||||
startTo?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean({ message: "allDay must be a boolean" })
|
||||
@Type(() => Boolean)
|
||||
allDay?: boolean;
|
||||
|
||||
@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;
|
||||
}
|
||||
56
apps/api/src/events/dto/update-event.dto.ts
Normal file
56
apps/api/src/events/dto/update-event.dto.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
IsString,
|
||||
IsOptional,
|
||||
IsUUID,
|
||||
IsDateString,
|
||||
IsBoolean,
|
||||
IsObject,
|
||||
MinLength,
|
||||
MaxLength,
|
||||
} from "class-validator";
|
||||
|
||||
/**
|
||||
* DTO for updating an existing event
|
||||
* All fields are optional to support partial updates
|
||||
*/
|
||||
export class UpdateEventDto {
|
||||
@IsOptional()
|
||||
@IsString({ message: "title must be a string" })
|
||||
@MinLength(1, { message: "title must not be empty" })
|
||||
@MaxLength(255, { message: "title must not exceed 255 characters" })
|
||||
title?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString({ message: "description must be a string" })
|
||||
@MaxLength(10000, { message: "description must not exceed 10000 characters" })
|
||||
description?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString({}, { message: "startTime must be a valid ISO 8601 date string" })
|
||||
startTime?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString({}, { message: "endTime must be a valid ISO 8601 date string" })
|
||||
endTime?: Date | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean({ message: "allDay must be a boolean" })
|
||||
allDay?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsString({ message: "location must be a string" })
|
||||
@MaxLength(500, { message: "location must not exceed 500 characters" })
|
||||
location?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject({ message: "recurrence must be an object" })
|
||||
recurrence?: Record<string, unknown> | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsUUID("4", { message: "projectId must be a valid UUID" })
|
||||
projectId?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsObject({ message: "metadata must be an object" })
|
||||
metadata?: Record<string, unknown>;
|
||||
}
|
||||
Reference in New Issue
Block a user