This commit is contained in:
Matthieu
2026-03-31 17:53:30 +02:00
parent e0f761da2b
commit 958a00c8fc
21 changed files with 281 additions and 144 deletions

View File

@@ -1,5 +1,6 @@
import { useApi } from '~/composables/useApi'
import type { ConstructeurLinkEntry } from '~/shared/constructeurUtils'
import { extractCollection } from '~/shared/utils/apiHelpers'
type EntityType = 'machine' | 'piece' | 'composant' | 'product'
@@ -25,7 +26,7 @@ const ENTITY_PLURALS: Record<EntityType, string> = {
}
export function useConstructeurLinks() {
const { get, post, patch, del } = useApi()
const { get, post, patch, delete: del } = useApi()
const fetchLinks = async (
entityType: EntityType,
@@ -34,11 +35,11 @@ export function useConstructeurLinks() {
const endpoint = ENDPOINTS[entityType]
const key = ENTITY_KEYS[entityType]
const plural = ENTITY_PLURALS[entityType]
const result = await get(`${endpoint}?${key}=/api/${plural}/${entityId}`)
const url = `${endpoint}?${key}=/api/${plural}/${entityId}`
const result = await get(url)
if (!result.success || !result.data) return []
const data = result.data as Record<string, any>
const members = data['hydra:member'] ?? (Array.isArray(data) ? data : [])
const members = extractCollection(result.data)
if (!Array.isArray(members)) return []
return members.map((link: any) => ({