feat(piece) : add quantity field to piece types, sanitization and hydration
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,9 @@ export const normalizeStructureForSave = (input: any): any => {
|
||||
if (piece.reference) {
|
||||
payload.reference = piece.reference
|
||||
}
|
||||
if ((piece as any).quantity !== undefined && (piece as any).quantity >= 1) {
|
||||
payload.quantity = (piece as any).quantity
|
||||
}
|
||||
return payload
|
||||
}) as any
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ export const hydratePieces = (pieces: any[]): ComponentModelPiece[] => {
|
||||
reference: piece?.reference ?? '',
|
||||
familyCode: piece?.familyCode ?? piece?.typePiece?.code ?? '',
|
||||
role: piece?.role ?? '',
|
||||
...(piece?.quantity !== undefined && piece.quantity >= 1 ? { quantity: piece.quantity } : {}),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -175,6 +176,7 @@ export const mapComponentPieces = (pieces: any[]): ComponentModelPiece[] => {
|
||||
typePieceLabel: piece?.typePieceLabel ?? piece?.typePiece?.name ?? '',
|
||||
familyCode: piece?.familyCode ?? piece?.typePiece?.code ?? '',
|
||||
role: piece?.role ?? '',
|
||||
...(piece?.quantity !== undefined && piece.quantity >= 1 ? { quantity: piece.quantity } : {}),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,8 @@ export const sanitizePieces = (pieces: any[]): ComponentModelPiece[] => {
|
||||
const rawRole = typeof piece?.role === 'string' ? piece.role.trim() : ''
|
||||
const role = rawRole.length > 0 ? rawRole : undefined
|
||||
|
||||
const quantity = typeof piece?.quantity === 'number' && piece.quantity >= 1 ? piece.quantity : undefined
|
||||
|
||||
if (!typePieceId && !typePieceLabel && !reference && !familyCode) {
|
||||
return null
|
||||
}
|
||||
@@ -182,6 +184,9 @@ export const sanitizePieces = (pieces: any[]): ComponentModelPiece[] => {
|
||||
if (typePieceLabel) {
|
||||
result.typePieceLabel = typePieceLabel
|
||||
}
|
||||
if (quantity !== undefined) {
|
||||
result.quantity = quantity
|
||||
}
|
||||
return result
|
||||
})
|
||||
.filter((piece): piece is ComponentModelPiece => !!piece)
|
||||
|
||||
Reference in New Issue
Block a user