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.
33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
import type { CommercialReport, CommercialReportWrite } from './dto/commercial-report'
|
|
import type { HydraCollection } from '~/utils/api'
|
|
import { extractHydraMembers } from '~/utils/api'
|
|
|
|
type Owner = { client?: string, prospect?: string, prestataire?: string }
|
|
|
|
export function useCommercialReportService() {
|
|
const api = useApi()
|
|
|
|
async function getByOwner(owner: Owner): Promise<CommercialReport[]> {
|
|
const data = await api.get<HydraCollection<CommercialReport>>('/commercial_reports', owner as Record<string, unknown>)
|
|
return extractHydraMembers(data)
|
|
}
|
|
|
|
async function create(payload: CommercialReportWrite): Promise<CommercialReport> {
|
|
return api.post<CommercialReport>('/commercial_reports', payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'directory.reports.saved',
|
|
})
|
|
}
|
|
|
|
async function update(id: number, payload: Partial<CommercialReportWrite>): Promise<CommercialReport> {
|
|
return api.patch<CommercialReport>(`/commercial_reports/${id}`, payload as Record<string, unknown>, {
|
|
toastSuccessKey: 'directory.reports.saved',
|
|
})
|
|
}
|
|
|
|
async function remove(id: number): Promise<void> {
|
|
await api.delete(`/commercial_reports/${id}`, {}, { toastSuccessKey: 'directory.reports.deleted' })
|
|
}
|
|
|
|
return { getByOwner, create, update, remove }
|
|
}
|