feat: projects with context - schema, API, frontend page, task assignment (HQ-17, HQ-21)

This commit is contained in:
2026-01-29 05:05:20 +00:00
parent 8685548206
commit b0559cdbc8
10 changed files with 963 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
import type { Task } from "./types";
import type { Task, Project, ProjectWithTasks } from "./types";
const BASE = "/api/tasks";
@@ -64,6 +64,57 @@ export async function deleteTask(id: string, token?: string): Promise<void> {
if (!res.ok) throw new Error("Failed to delete task");
}
// ─── Projects API ───
const PROJECTS_BASE = "/api/projects";
export async function fetchProjects(): Promise<Project[]> {
const res = await fetch(PROJECTS_BASE, { credentials: "include" });
if (!res.ok) throw new Error(res.status === 401 ? "Unauthorized" : "Failed to fetch projects");
return res.json();
}
export async function fetchProject(id: string): Promise<ProjectWithTasks> {
const res = await fetch(`${PROJECTS_BASE}/${id}`, { credentials: "include" });
if (!res.ok) throw new Error("Failed to fetch project");
return res.json();
}
export async function createProject(
project: { name: string; description?: string; context?: string; repos?: string[]; links?: { label: string; url: string }[] }
): Promise<Project> {
const res = await fetch(PROJECTS_BASE, {
method: "POST",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(project),
});
if (!res.ok) throw new Error("Failed to create project");
return res.json();
}
export async function updateProject(
id: string,
updates: Record<string, any>
): Promise<Project> {
const res = await fetch(`${PROJECTS_BASE}/${id}`, {
method: "PATCH",
credentials: "include",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(updates),
});
if (!res.ok) throw new Error("Failed to update project");
return res.json();
}
export async function deleteProject(id: string): Promise<void> {
const res = await fetch(`${PROJECTS_BASE}/${id}`, {
method: "DELETE",
credentials: "include",
});
if (!res.ok) throw new Error("Failed to delete project");
}
// Admin API
export async function fetchUsers(): Promise<any[]> {
const res = await fetch("/api/admin/users", { credentials: "include" });