Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Update WorkspaceGuard to support query string as fallback (backward compatibility) - Priority order: Header > Param > Body > Query - Update web client to send workspace ID via X-Workspace-Id header (recommended) - Extend apiRequest helpers to accept workspace ID option - Update fetchTasks to use header instead of query parameter - Add comprehensive tests for all workspace ID transmission methods - Tests passing: API 11 tests, Web 6 new tests (total 494) This ensures consistent workspace ID handling with proper multi-tenant isolation while maintaining backward compatibility with existing query string approaches. Fixes #194 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
115 lines
3.0 KiB
TypeScript
115 lines
3.0 KiB
TypeScript
/**
|
|
* 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<Task[]> {
|
|
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<ApiResponse<Task[]>>(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"),
|
|
},
|
|
];
|