import type { Contact, ContactWrite } from './dto/contact' import type { HydraCollection } from '~/utils/api' import { extractHydraMembers } from '~/utils/api' type Owner = { client?: string, prospect?: string } export function useContactService() { const api = useApi() async function getByOwner(owner: Owner): Promise { const data = await api.get>('/contacts', owner as Record) return extractHydraMembers(data) } async function create(payload: ContactWrite): Promise { return api.post('/contacts', payload as Record, { toastSuccessKey: 'directory.contacts.saved', }) } async function update(id: number, payload: Partial): Promise { return api.patch(`/contacts/${id}`, payload as Record, { toastSuccessKey: 'directory.contacts.saved', }) } async function remove(id: number): Promise { await api.delete(`/contacts/${id}`, {}, { toastSuccessKey: 'directory.contacts.deleted' }) } return { getByOwner, create, update, remove } }