Files
Lesstime/frontend/modules/directory/services/contacts.ts
T
Matthieu 5764d8f472
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m20s
Pull Request — Quality gate / Frontend (build) (pull_request) Successful in 1m26s
feat(directory) : type prestataire, validateurs front, autocomplete adresse BAN
- Prestataire : entité/repo + ressource API Platform (RBAC directory.providers.*),
  ownership prestataire sur contacts/adresses/comptes-rendus (CHECK XOR à 3),
  DTO/service/drawer/fiche détail + onglet dédié dans le répertoire.
- Prospect : société uniquement (suppression du champ name, company requis) ;
  migration de backfill, conversion prospect→client et MCP adaptés.
- Champ site web sur client/prospect/prestataire (entités, DTO, onglet Information, MCP).
- Validateurs front email / téléphone FR (0549200910) / URL sur Information et Contacts,
  enregistrement bloqué tant qu'un champ est invalide.
- Autocomplete adresse branché sur la Base Adresse Nationale (api-adresse.data.gouv.fr)
  avec mode dégradé en saisie libre.
- Administration : retrait de l'onglet Clients.
2026-06-24 17:55:09 +02:00

33 lines
1.2 KiB
TypeScript

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