import { appendChange } from '../../infrastructure/sync/changeLogRepository' import { getContactRepository } from '../../infrastructure/repositories/repositoryFactory' const contactRepo = () => getContactRepository() export async function listContacts(search = '') { return contactRepo().list(search) } export async function getContactById(id) { return contactRepo().getById(id) } export async function createContact(payload) { const created = await contactRepo().create(payload) await appendChange({ entityType: 'contact', entityId: created.id, op: 'created', payloadPatch: created, }) return created } export async function updateContact(id, payload) { const updated = await contactRepo().update(id, payload) await appendChange({ entityType: 'contact', entityId: id, op: 'updated', payloadPatch: payload, }) return updated } export async function deleteContact(id) { await contactRepo().remove(id) await appendChange({ entityType: 'contact', entityId: id, op: 'deleted', payloadPatch: {}, }) }