5764d8f472
- 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.
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { Prestataire, PrestataireWrite } from './dto/prestataire'
|
|
import type { HydraCollection } from '~/utils/api'
|
|
import { extractHydraMembers } from '~/utils/api'
|
|
|
|
export function usePrestataireService() {
|
|
const api = useApi()
|
|
|
|
async function getAll(): Promise<Prestataire[]> {
|
|
const data = await api.get<HydraCollection<Prestataire>>('/prestataires')
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function getById(id: number): Promise<Prestataire> {
|
|
return api.get<Prestataire>(`/prestataires/${id}`)
|
|
}
|
|
|
|
async function create(payload: PrestataireWrite): Promise<Prestataire> {
|
|
return api.post<Prestataire>('/prestataires', payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'prestataires.created',
|
|
})
|
|
}
|
|
|
|
async function update(id: number, payload: Partial<PrestataireWrite>): Promise<Prestataire> {
|
|
return api.patch<Prestataire>(`/prestataires/${id}`, payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'prestataires.updated',
|
|
})
|
|
}
|
|
|
|
async function remove(id: number): Promise<void> {
|
|
await api.delete(`/prestataires/${id}`, {}, {
|
|
toastSuccessKey: 'prestataires.deleted',
|
|
})
|
|
}
|
|
|
|
return { getAll, getById, create, update, remove }
|
|
}
|