40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
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 }
|
|
}
|