diff --git a/frontend/services/client-tickets.ts b/frontend/services/client-tickets.ts new file mode 100644 index 0000000..18480f9 --- /dev/null +++ b/frontend/services/client-tickets.ts @@ -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): Promise { + const data = await api.get>('/client_tickets', params) + return extractHydraMembers(data) + } + + async function getById(id: number): Promise { + return await api.get(`/client_tickets/${id}`) + } + + async function create(data: ClientTicketWrite): Promise { + return await api.post('/client_tickets', data as Record, { + toastSuccessKey: 'clientTicket.created', + }) + } + + async function updateStatus(id: number, status: string, statusComment?: string): Promise { + return await api.patch(`/client_tickets/${id}`, { + status, + ...(statusComment ? { statusComment } : {}), + }, { + toastSuccessKey: 'clientTicket.statusUpdated', + }) + } + + async function remove(id: number): Promise { + await api.delete(`/client_tickets/${id}`, {}, { + toastSuccessKey: 'clientTicket.deleted', + }) + } + + return { getAll, getById, create, updateStatus, remove } +}