feat(frontend) : add client-tickets service

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-15 19:30:32 +01:00
parent 4fbbead3e3
commit bfd418851e

View File

@@ -0,0 +1,39 @@
import type { ClientTicket, ClientTicketWrite } from './dto/client-ticket'
import type { HydraCollection } from '~/utils/api'
import { extractHydraMembers } from '~/utils/api'
export function useClientTicketService() {
const api = useApi()
async function getAll(params?: Record<string, string | number>): Promise<ClientTicket[]> {
const data = await api.get<HydraCollection<ClientTicket>>('/client_tickets', params)
return extractHydraMembers(data)
}
async function getById(id: number): Promise<ClientTicket> {
return await api.get<ClientTicket>(`/client_tickets/${id}`)
}
async function create(data: ClientTicketWrite): Promise<ClientTicket> {
return await api.post<ClientTicket>('/client_tickets', data as Record<string, unknown>, {
toastSuccessKey: 'clientTicket.created',
})
}
async function updateStatus(id: number, status: string, statusComment?: string): Promise<ClientTicket> {
return await api.patch<ClientTicket>(`/client_tickets/${id}`, {
status,
...(statusComment ? { statusComment } : {}),
}, {
toastSuccessKey: 'clientTicket.statusUpdated',
})
}
async function remove(id: number): Promise<void> {
await api.delete(`/client_tickets/${id}`, {}, {
toastSuccessKey: 'clientTicket.deleted',
})
}
return { getAll, getById, create, updateStatus, remove }
}