refactor: prepare multi-machine inventory associations

This commit is contained in:
Matthieu
2025-10-08 16:23:49 +02:00
parent c23ba3a587
commit 48a74b74d7
19 changed files with 1166 additions and 297 deletions

View File

@@ -53,28 +53,38 @@ export function normalizeComponentModelStructure(
return {
familyCode:
ensureString(
candidate?.familyCode ?? candidate?.name ?? candidate?.typePieceLabel ?? 'UNKNOWN',
candidate?.familyCode ??
candidate?.name ??
candidate?.typePieceLabel ??
'UNKNOWN',
).trim() || 'UNKNOWN',
role: sanitizeRole(candidate?.role),
} as ComponentModelStructure['pieces'][number];
});
const customFields = toArray((structure as any)?.customFields).map((field) => {
const candidate = field as Record<string, unknown> | null | undefined;
const key = ensureString(candidate?.key ?? candidate?.name ?? 'unknown').trim();
const customFields = toArray((structure as any)?.customFields).map(
(field) => {
const candidate = field as Record<string, unknown> | null | undefined;
const key = ensureString(
candidate?.key ?? candidate?.name ?? 'unknown',
).trim();
return {
key: key || 'unknown',
value: candidate?.value ?? null,
};
});
return {
key: key || 'unknown',
value: candidate?.value ?? null,
};
},
);
const rawSubcomponents = toArray(
(structure as any)?.subcomponents ?? (structure as any)?.subComponents,
);
const subcomponents = rawSubcomponents.map((subcomponent) => {
const candidate = subcomponent as Record<string, unknown> | null | undefined;
const candidate = subcomponent as
| Record<string, unknown>
| null
| undefined;
if (candidate?.modelId) {
return {
@@ -90,13 +100,15 @@ export function normalizeComponentModelStructure(
}
if (candidate?.typeComposantId) {
return {
typeComposantId: ensureString(candidate.typeComposantId).trim() || 'UNKNOWN',
typeComposantId:
ensureString(candidate.typeComposantId).trim() || 'UNKNOWN',
alias: sanitizeAlias(candidate?.alias ?? candidate?.name),
} as ComponentModelStructure['subcomponents'][number];
}
return {
familyCode: ensureString(candidate?.name ?? 'UNKNOWN').trim() || 'UNKNOWN',
familyCode:
ensureString(candidate?.name ?? 'UNKNOWN').trim() || 'UNKNOWN',
alias: sanitizeAlias(candidate?.alias ?? candidate?.name),
} as ComponentModelStructure['subcomponents'][number];
});