Task module

This commit is contained in:
Marek Lenczewski
2026-04-12 10:06:17 +02:00
parent efe0cfe361
commit 27b34eb90f
39 changed files with 2454 additions and 41 deletions

View File

@@ -0,0 +1,23 @@
const BASE = 'https://haushalt.ddev.site/api'
async function request(path, opts = {}) {
const res = await fetch(`${BASE}${path}`, {
headers: { 'Content-Type': 'application/json', ...(opts.headers ?? {}) },
...opts,
})
if (!res.ok) {
const body = await res.text().catch(() => '')
throw new Error(`API ${res.status} ${res.statusText}${body ? `: ${body}` : ''}`)
}
return res.status === 204 ? null : res.json()
}
export const taskApi = {
list: (filter) => request(`/tasks${filter ? `?filter=${filter}` : ''}`),
get: (id) => request(`/tasks/${id}`),
create: (data) => request('/tasks', { method: 'POST', body: JSON.stringify(data) }),
update: (id, data) => request(`/tasks/${id}`, { method: 'PUT', body: JSON.stringify(data) }),
remove: (id) => request(`/tasks/${id}`, { method: 'DELETE' }),
toggle: (id) => request(`/tasks/${id}/toggle`, { method: 'PATCH' }),
statuses: () => request('/tasks/statuses'),
}