/** * Task API Client * Handles task-related API requests */ import type { Task } from "@mosaic/shared"; import { TaskStatus, TaskPriority } from "@mosaic/shared"; import { apiGet, type ApiResponse } from "./client"; export interface TaskFilters { status?: TaskStatus; priority?: TaskPriority; workspaceId?: string; } /** * Fetch tasks with optional filters */ export async function fetchTasks(filters?: TaskFilters): Promise { const params = new URLSearchParams(); // Add filter parameters (not workspace ID - that goes in header) if (filters?.status) { params.append("status", filters.status); } if (filters?.priority) { params.append("priority", filters.priority); } const queryString = params.toString(); const endpoint = queryString ? `/api/tasks?${queryString}` : "/api/tasks"; // Pass workspaceId via header (X-Workspace-Id) instead of query string const response = await apiGet>(endpoint, filters?.workspaceId); return response.data; } /** * Mock tasks for development (until backend endpoints are ready) */ export const mockTasks: Task[] = [ { id: "task-1", title: "Review pull request", description: "Review and provide feedback on frontend PR", status: TaskStatus.IN_PROGRESS, priority: TaskPriority.HIGH, dueDate: new Date("2026-01-29"), creatorId: "user-1", assigneeId: "user-1", workspaceId: "workspace-1", projectId: null, parentId: null, sortOrder: 0, metadata: {}, completedAt: null, createdAt: new Date("2026-01-28"), updatedAt: new Date("2026-01-28"), }, { id: "task-2", title: "Update documentation", description: "Add setup instructions for new developers", status: TaskStatus.IN_PROGRESS, priority: TaskPriority.MEDIUM, dueDate: new Date("2026-01-30"), creatorId: "user-1", assigneeId: "user-1", workspaceId: "workspace-1", projectId: null, parentId: null, sortOrder: 1, metadata: {}, completedAt: null, createdAt: new Date("2026-01-28"), updatedAt: new Date("2026-01-28"), }, { id: "task-3", title: "Plan Q1 roadmap", description: "Define priorities for Q1 2026", status: TaskStatus.NOT_STARTED, priority: TaskPriority.HIGH, dueDate: new Date("2026-02-03"), creatorId: "user-1", assigneeId: "user-1", workspaceId: "workspace-1", projectId: null, parentId: null, sortOrder: 2, metadata: {}, completedAt: null, createdAt: new Date("2026-01-28"), updatedAt: new Date("2026-01-28"), }, { id: "task-4", title: "Research new libraries", description: "Evaluate options for state management", status: TaskStatus.PAUSED, priority: TaskPriority.LOW, dueDate: new Date("2026-02-10"), creatorId: "user-1", assigneeId: "user-1", workspaceId: "workspace-1", projectId: null, parentId: null, sortOrder: 3, metadata: {}, completedAt: null, createdAt: new Date("2026-01-28"), updatedAt: new Date("2026-01-28"), }, ];