84 行
2.4 KiB
TypeScript
84 行
2.4 KiB
TypeScript
import { apiRequestData } from "./http";
|
|
|
|
export type TodoPriority = "low" | "normal" | "high";
|
|
export type TodoStatus = "todo" | "doing" | "done" | "cancelled";
|
|
export type TodoSource = "manual" | "weekly_report";
|
|
|
|
export type TodoItem = {
|
|
id: string;
|
|
title: string;
|
|
description: string | null;
|
|
assigneeEmployeeId: string;
|
|
createdBy: string;
|
|
dueDate: string | null;
|
|
priority: TodoPriority;
|
|
status: TodoStatus;
|
|
source: TodoSource;
|
|
projectId: string | null;
|
|
project: { id: string; projectNo: string; name: string } | null;
|
|
createdAt: string | null;
|
|
updatedAt: string | null;
|
|
completedAt: string | null;
|
|
assignee: { id: string; employeeNo: string; name: string } | null;
|
|
creator: { id: string; employeeNo: string; name: string } | null;
|
|
};
|
|
|
|
export async function fetchTodos(params: {
|
|
status?: TodoStatus;
|
|
scope?: "mine" | "team";
|
|
assigneeId?: string;
|
|
q?: string;
|
|
} = {}) {
|
|
const search = new URLSearchParams();
|
|
if (params.status) search.set("status", params.status);
|
|
if (params.scope) search.set("scope", params.scope);
|
|
if (params.assigneeId) search.set("assigneeId", params.assigneeId);
|
|
if (params.q) search.set("q", params.q);
|
|
const suffix = search.toString() ? `?${search.toString()}` : "";
|
|
return apiRequestData<{ items: TodoItem[] }>(`/api/todos${suffix}`);
|
|
}
|
|
|
|
export async function createTodo(payload: {
|
|
title: string;
|
|
description?: string | null;
|
|
assigneeEmployeeId?: string;
|
|
dueDate?: string | null;
|
|
priority?: TodoPriority;
|
|
source?: TodoSource;
|
|
projectId?: string | null;
|
|
}) {
|
|
return apiRequestData<{ item: TodoItem }>("/api/todos", {
|
|
method: "POST",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function patchTodo(id: string, payload: Partial<{
|
|
title: string;
|
|
description: string | null;
|
|
assigneeEmployeeId: string;
|
|
dueDate: string | null;
|
|
priority: TodoPriority;
|
|
status: TodoStatus;
|
|
projectId: string | null;
|
|
}>) {
|
|
return apiRequestData<{ item: TodoItem }>(`/api/todos/${id}`, {
|
|
method: "PATCH",
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export async function completeTodo(id: string) {
|
|
return apiRequestData<{ item: TodoItem }>(`/api/todos/${id}/complete`, {
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
});
|
|
}
|
|
|
|
export async function cancelTodo(id: string) {
|
|
return apiRequestData<{ item: TodoItem }>(`/api/todos/${id}/cancel`, {
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
});
|
|
}
|