/
NeGaTiVe333
/
Frontend
Обзор
Документация
Войти
/
NeGaTiVe333
/
Frontend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/api/tasks.ts
76 строк
2 KB
NeGaTiVe369
feat: готовый проект
05 дек 2025, 18:59
05 дек 2025, 18:59
ac252ce
Код
Авторство
О чём код?
import api from "./client"; export type TaskStatus = "todo" | "in_progress" | "done" | string; export type Task = { id: string; title: string; description?: string; status: TaskStatus; dueDate: string | null; tags?: string[]; ownerId: string; createdAt: string; updatedAt: string; }; export type TaskListMeta = { total: number; page: number; perPage: number; totalPages: number; }; export type TaskListResponse = { meta: TaskListMeta; data: Task[]; }; export type TaskQueryParams = { q?: string; tag?: string; page?: number; perPage?: number; }; // GET /api/v2/tasks export async function getTasks( params: TaskQueryParams ): Promise<TaskListResponse> { const res = await api.get<TaskListResponse>("/api/v2/tasks", { params }); return res.data; } export type TaskCreate = { title: string; description?: string; dueDate?: string | null; tags?: string[]; }; // POST /api/v2/tasks с Idempotency-Key export async function createTask( data: TaskCreate, idempotencyKey: string ): Promise<Task> { const res = await api.post<Task>("/api/v2/tasks", data, { headers: { "Idempotency-Key": idempotencyKey, }, }); return res.data; } // PATCH /api/v2/tasks/:id export async function updateTask( id: string, data: Partial<TaskCreate & { status: TaskStatus }> ): Promise<Task> { const res = await api.patch<Task>(`/api/v2/tasks/${id}`, data); return res.data; } // DELETE /api/v2/tasks/:id export async function deleteTask(id: string): Promise<void> { await api.delete(`/api/v2/tasks/${id}`); }