Add kanban board with drag-and-drop, backlog section, task/group drawers, DTOs, services, and i18n translations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { Project, ProjectWrite } from './dto/project'
|
|
import type { HydraCollection } from '~/utils/api'
|
|
import { extractHydraMembers } from '~/utils/api'
|
|
|
|
export function useProjectService() {
|
|
const api = useApi()
|
|
|
|
async function getAll(): Promise<Project[]> {
|
|
const data = await api.get<HydraCollection<Project>>('/projects')
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function getById(id: number): Promise<Project> {
|
|
return api.get<Project>(`/projects/${id}`)
|
|
}
|
|
|
|
async function create(payload: ProjectWrite): Promise<Project> {
|
|
return api.post<Project>('/projects', payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'projects.created',
|
|
})
|
|
}
|
|
|
|
async function update(id: number, payload: Partial<ProjectWrite>): Promise<Project> {
|
|
return api.patch<Project>(`/projects/${id}`, payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'projects.updated',
|
|
})
|
|
}
|
|
|
|
async function remove(id: number): Promise<void> {
|
|
await api.delete(`/projects/${id}`, {}, {
|
|
toastSuccessKey: 'projects.deleted',
|
|
})
|
|
}
|
|
|
|
return { getAll, getById, create, update, remove }
|
|
}
|