Files
Lesstime/frontend/services/projects.ts
matthieu 0733ac16cd feat : add project archiving feature
Allow projects to be archived/unarchived from the ProjectDrawer, with a
toggle filter on the projects page to show/hide archived projects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 08:58:29 +01:00

38 lines
1.4 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(params?: { archived?: boolean }): Promise<Project[]> {
const query = params?.archived !== undefined ? `?archived=${params.archived}` : ''
const data = await api.get<HydraCollection<Project>>(`/projects${query}`)
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>, options?: { toastSuccessKey?: string }): Promise<Project> {
return api.patch<Project>(`/projects/${id}`, payload as Record<string, unknown>, {
toastSuccessKey: options?.toastSuccessKey ?? 'projects.updated',
})
}
async function remove(id: number): Promise<void> {
await api.delete(`/projects/${id}`, {}, {
toastSuccessKey: 'projects.deleted',
})
}
return { getAll, getById, create, update, remove }
}