/** * Projects API Client * Handles project-related API requests */ import { apiGet, apiPost, apiPatch, apiDelete } from "./client"; /** * Project status enum (matches backend ProjectStatus) */ export enum ProjectStatus { PLANNING = "PLANNING", ACTIVE = "ACTIVE", PAUSED = "PAUSED", COMPLETED = "COMPLETED", ARCHIVED = "ARCHIVED", } /** * Project response interface (matches Prisma Project model) */ export interface Project { id: string; workspaceId: string; name: string; description: string | null; status: ProjectStatus; priority?: string | null; startDate: string | null; dueDate?: string | null; endDate: string | null; creatorId: string; domainId: string | null; color: string | null; metadata: Record; createdAt: string; updatedAt: string; } /** * Minimal creator details included on project detail response */ export interface ProjectCreator { id: string; name: string | null; email: string; } /** * Task row included on project detail response */ export interface ProjectTaskSummary { id: string; title: string; status: string; priority: string; dueDate: string | null; } /** * Event row included on project detail response */ export interface ProjectEventSummary { id: string; title: string; startTime: string; endTime: string | null; } /** * Counts included on project detail response */ export interface ProjectDetailCounts { tasks: number; events: number; } /** * Single-project response with related details */ export interface ProjectDetail extends Project { creator: ProjectCreator; tasks: ProjectTaskSummary[]; events: ProjectEventSummary[]; _count: ProjectDetailCounts; } /** * DTO for creating a new project */ export interface CreateProjectDto { name: string; description?: string; status?: ProjectStatus; startDate?: string; endDate?: string; color?: string; metadata?: Record; } /** * DTO for updating an existing project */ export interface UpdateProjectDto { name?: string; description?: string | null; status?: ProjectStatus; startDate?: string | null; endDate?: string | null; color?: string | null; metadata?: Record; } /** * Fetch all projects for a workspace */ export async function fetchProjects(workspaceId?: string): Promise { const response = await apiGet<{ data: Project[]; meta?: unknown }>("/api/projects", workspaceId); return response.data; } /** * Fetch a single project by ID */ export async function fetchProject(id: string, workspaceId?: string): Promise { return apiGet(`/api/projects/${id}`, workspaceId); } /** * Create a new project */ export async function createProject( data: CreateProjectDto, workspaceId?: string ): Promise { return apiPost("/api/projects", data, workspaceId); } /** * Update an existing project */ export async function updateProject( id: string, data: UpdateProjectDto, workspaceId?: string ): Promise { return apiPatch(`/api/projects/${id}`, data, workspaceId); } /** * Delete a project */ export async function deleteProject(id: string, workspaceId?: string): Promise { await apiDelete>(`/api/projects/${id}`, workspaceId); }