Critical fixes: - Make MigrateConstructeurLinks migration no-op (legacy tables already dropped) - Add explicit ON CONFLICT (id) target in RestoreConstructeurLinks migration - Replace N+1 queries with 4 bulk GROUP BY in ConstructeurStatsController - Declare missing versionListRef template ref in machine detail page - Add missing await on removeMachineDocument, cast activeTab as string Important fixes: - Add lang="ts" to ToastContainer and constructeurs page - Type entityType as union in UsedInSection/useUsedIn - Remove dead duration param from showError - Update back-link props to new /catalogues/* URLs (3 pages) - Replace raw error blocks with EmptyState in component/piece detail pages - Type handleFillEntity params and machineInfoCardRef Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import type { Ref } from 'vue'
|
|
|
|
interface UsedInMachine {
|
|
id: string
|
|
name: string
|
|
site?: { id: string; name: string } | null
|
|
}
|
|
|
|
interface UsedInEntity {
|
|
id: string
|
|
name: string
|
|
}
|
|
|
|
interface UsedInData {
|
|
machines: UsedInMachine[]
|
|
composants: UsedInEntity[]
|
|
pieces: UsedInEntity[]
|
|
}
|
|
|
|
export function useUsedIn(entityType: Ref<'composants' | 'pieces' | 'products'>, entityId: Ref<string | null>) {
|
|
const data = ref<UsedInData>({ machines: [], composants: [], pieces: [] })
|
|
const loading = ref(false)
|
|
|
|
const api = useApi()
|
|
|
|
const load = async () => {
|
|
if (!entityId.value) return
|
|
loading.value = true
|
|
try {
|
|
const result = await api.get(`/${entityType.value}/${entityId.value}/used-in`)
|
|
if (result.success && result.data) {
|
|
data.value = {
|
|
machines: result.data.machines || [],
|
|
composants: result.data.composants || [],
|
|
pieces: result.data.pieces || [],
|
|
}
|
|
}
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const totalCount = computed(() =>
|
|
data.value.machines.length + data.value.composants.length + data.value.pieces.length
|
|
)
|
|
|
|
watch(entityId, (val) => {
|
|
if (val) load()
|
|
}, { immediate: true })
|
|
|
|
return { data, loading, totalCount, load }
|
|
}
|