Map seeded component models to type identifiers

This commit is contained in:
MatthieuTD
2025-10-02 09:33:59 +02:00
parent 6f52b27efc
commit 44fd4bb8c7

View File

@@ -4311,21 +4311,27 @@ function buildComponentModelStructure(
template?.usage ?? template?.role ?? template?.notes ?? null, template?.usage ?? template?.role ?? template?.notes ?? null,
); );
if (pieceTypes[typeCode]) { const pieceType = pieceTypes[typeCode];
pieces.push( if (pieceType) {
normalizedRole const entry: Record<string, unknown> = { typePieceId: pieceType.id };
? { familyCode: typeCode, role: normalizedRole } if (normalizedRole) {
: { familyCode: typeCode }, entry.role = normalizedRole;
); }
entry.familyCode = typeCode;
pieces.push(entry as ComponentModelStructure['pieces'][number]);
continue; continue;
} }
if (componentTypes[typeCode]) { const subcomponentType = componentTypes[typeCode];
subcomponents.push( if (subcomponentType) {
normalizedRole const entry: Record<string, unknown> = {
? { familyCode: typeCode, alias: normalizedRole } typeComposantId: subcomponentType.id,
: { familyCode: typeCode }, familyCode: typeCode,
); };
if (normalizedRole) {
entry.alias = normalizedRole;
}
subcomponents.push(entry as ComponentModelStructure['subcomponents'][number]);
continue; continue;
} }
@@ -4347,6 +4353,8 @@ function buildComponentModelStructure(
? (template?.suggestedModelCodes as string[]) ? (template?.suggestedModelCodes as string[])
: []; : [];
const componentType = typeCode ? componentTypes[typeCode] : undefined;
if (suggestedModels.length > 0) { if (suggestedModels.length > 0) {
suggestedModels.forEach((modelCode, index) => { suggestedModels.forEach((modelCode, index) => {
const hint = const hint =
@@ -4354,21 +4362,37 @@ function buildComponentModelStructure(
? `${normalizedAlias} #${index + 1}` ? `${normalizedAlias} #${index + 1}`
: normalizedAlias; : normalizedAlias;
const fallbackFamily = typeCode || String(modelCode ?? '').trim() || 'UNKNOWN'; const fallbackFamily = typeCode || String(modelCode ?? '').trim() || 'UNKNOWN';
subcomponents.push( const entry: Record<string, unknown> = hint ? { alias: hint } : {};
hint
? { familyCode: fallbackFamily, alias: hint } if (componentType) {
: { familyCode: fallbackFamily }, entry.typeComposantId = componentType.id;
); entry.familyCode = typeCode;
} else {
entry.familyCode = fallbackFamily;
}
subcomponents.push(entry as ComponentModelStructure['subcomponents'][number]);
}); });
continue; continue;
} }
if (typeCode) { if (typeCode) {
if (componentType) {
const entry: Record<string, unknown> = {
typeComposantId: componentType.id,
familyCode: typeCode,
};
if (normalizedAlias) {
entry.alias = normalizedAlias;
}
subcomponents.push(entry as ComponentModelStructure['subcomponents'][number]);
} else {
subcomponents.push( subcomponents.push(
normalizedAlias normalizedAlias
? { familyCode: typeCode, alias: normalizedAlias } ? { familyCode: typeCode, alias: normalizedAlias }
: { familyCode: typeCode }, : { familyCode: typeCode },
); );
}
continue; continue;
} }
} }