7446b7dca9
Tranche 4 of LST-65. Companion to the backend module migration.
- Move pages (my-tasks, projects, projects/[id]/{index,groups,archives}),
18 components (project + task), 10 services and 10 DTOs into
frontend/modules/project-management/ (auto-detected layer).
- Rewrite explicit ~/services/* and ~/services/dto/* imports across 38
consumers (admin tabs, mail modals, dashboard, mail page, layout) including
the time-tracking module whose DTOs referenced project/task/task-tag.
- clients.ts and shared DTOs (client, user-data) stay at the root.
- Routes /my-tasks, /projects, /projects/:id(/groups|/archives) preserved;
i18n stays global.
nuxt build passes; routes confirmed.
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import type { Task, TaskWrite } from './dto/task'
|
|
import type { HydraCollection } from '~/utils/api'
|
|
import { extractHydraMembers } from '~/utils/api'
|
|
|
|
export function useTaskService() {
|
|
const api = useApi()
|
|
|
|
async function getAll(): Promise<Task[]> {
|
|
const data = await api.get<HydraCollection<Task>>('/tasks')
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function getByProject(projectId: number, archived = false): Promise<Task[]> {
|
|
const data = await api.get<HydraCollection<Task>>('/tasks', {
|
|
project: `/api/projects/${projectId}`,
|
|
archived,
|
|
})
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function getFiltered(params: Record<string, string | number | boolean | string[]>): Promise<Task[]> {
|
|
const data = await api.get<HydraCollection<Task>>('/tasks', params as Record<string, unknown>)
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function create(payload: TaskWrite): Promise<Task> {
|
|
return api.post<Task>('/tasks', payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'tasks.created',
|
|
})
|
|
}
|
|
|
|
async function update(id: number, payload: Partial<TaskWrite>): Promise<Task> {
|
|
return api.patch<Task>(`/tasks/${id}`, payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'tasks.updated',
|
|
})
|
|
}
|
|
|
|
async function remove(id: number): Promise<void> {
|
|
await api.delete(`/tasks/${id}`, {}, {
|
|
toastSuccessKey: 'tasks.deleted',
|
|
})
|
|
}
|
|
|
|
return { getAll, getByProject, getFiltered, create, update, remove }
|
|
}
|