chore: update frontend configuration
This commit is contained in:
@@ -67,18 +67,6 @@ const sanitizePieces = (pieces: any[]): any[] => {
|
||||
|
||||
return pieces
|
||||
.map((piece) => {
|
||||
const name = typeof piece?.name === 'string' ? piece.name.trim() : ''
|
||||
if (!name) {
|
||||
return null
|
||||
}
|
||||
|
||||
const reference = typeof piece?.reference === 'string' && piece.reference.trim().length > 0
|
||||
? piece.reference.trim()
|
||||
: undefined
|
||||
|
||||
const quantity = Number(piece?.quantity)
|
||||
const normalizedQuantity = Number.isFinite(quantity) && quantity > 0 ? quantity : undefined
|
||||
|
||||
const rawTypePieceId = typeof piece?.typePieceId === 'string'
|
||||
? piece.typePieceId.trim()
|
||||
: typeof piece?.typePiece?.id === 'string'
|
||||
@@ -93,6 +81,19 @@ const sanitizePieces = (pieces: any[]): any[] => {
|
||||
: ''
|
||||
const typePieceLabel = rawTypePieceLabel.length > 0 ? rawTypePieceLabel : undefined
|
||||
|
||||
const rawName = typeof piece?.name === 'string' ? piece.name.trim() : ''
|
||||
const name = rawName || typePieceLabel || ''
|
||||
if (!name) {
|
||||
return null
|
||||
}
|
||||
|
||||
const reference = typeof piece?.reference === 'string' && piece.reference.trim().length > 0
|
||||
? piece.reference.trim()
|
||||
: undefined
|
||||
|
||||
const quantity = Number(piece?.quantity)
|
||||
const normalizedQuantity = Number.isFinite(quantity) && quantity > 0 ? quantity : undefined
|
||||
|
||||
const result: Record<string, unknown> = { name }
|
||||
if (reference !== undefined) {
|
||||
result.reference = reference
|
||||
@@ -118,7 +119,22 @@ const sanitizeSubComponents = (components: any[]): any[] => {
|
||||
|
||||
return components
|
||||
.map((component) => {
|
||||
const name = typeof component?.name === 'string' ? component.name.trim() : ''
|
||||
const rawTypeComposantId = typeof component?.typeComposantId === 'string'
|
||||
? component.typeComposantId.trim()
|
||||
: typeof component?.typeComposant?.id === 'string'
|
||||
? component.typeComposant.id.trim()
|
||||
: ''
|
||||
const typeComposantId = rawTypeComposantId.length > 0 ? rawTypeComposantId : undefined
|
||||
|
||||
const rawTypeComposantLabel = typeof component?.typeComposantLabel === 'string'
|
||||
? component.typeComposantLabel.trim()
|
||||
: typeof component?.typeComposant?.name === 'string'
|
||||
? component.typeComposant.name.trim()
|
||||
: ''
|
||||
const typeComposantLabel = rawTypeComposantLabel.length > 0 ? rawTypeComposantLabel : undefined
|
||||
|
||||
const rawName = typeof component?.name === 'string' ? component.name.trim() : ''
|
||||
const name = rawName || typeComposantLabel || ''
|
||||
if (!name) {
|
||||
return null
|
||||
}
|
||||
@@ -147,6 +163,12 @@ const sanitizeSubComponents = (components: any[]): any[] => {
|
||||
if (normalizedQuantity !== undefined) {
|
||||
result.quantity = normalizedQuantity
|
||||
}
|
||||
if (typeComposantId) {
|
||||
result.typeComposantId = typeComposantId
|
||||
}
|
||||
if (typeComposantLabel) {
|
||||
result.typeComposantLabel = typeComposantLabel
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
@@ -183,9 +205,9 @@ const hydratePieces = (pieces: any[]): any[] => {
|
||||
}
|
||||
|
||||
return pieces.map((piece) => ({
|
||||
name: piece?.name ?? '',
|
||||
name: piece?.name ?? piece?.typePiece?.name ?? piece?.typePieceLabel ?? '',
|
||||
reference: piece?.reference ?? '',
|
||||
quantity: piece?.quantity ?? undefined,
|
||||
quantity: piece?.quantity ?? piece?.quantite ?? undefined,
|
||||
typePieceId: piece?.typePieceId ?? piece?.typePiece?.id ?? '',
|
||||
typePieceLabel: piece?.typePieceLabel ?? piece?.typePiece?.name ?? '',
|
||||
}))
|
||||
@@ -197,9 +219,11 @@ const hydrateSubComponents = (components: any[]): any[] => {
|
||||
}
|
||||
|
||||
return components.map((component) => ({
|
||||
name: component?.name ?? '',
|
||||
name: component?.name ?? component?.typeComposant?.name ?? component?.typeComposantLabel ?? '',
|
||||
description: component?.description ?? '',
|
||||
quantity: component?.quantity ?? undefined,
|
||||
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
||||
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
||||
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
||||
customFields: hydrateCustomFields(component?.customFields),
|
||||
pieces: hydratePieces(component?.pieces),
|
||||
subComponents: hydrateSubComponents(component?.subComponents),
|
||||
@@ -243,9 +267,11 @@ const mapComponentPieces = (pieces: any[]) => {
|
||||
return []
|
||||
}
|
||||
return pieces.map((piece) => ({
|
||||
name: piece?.name ?? '',
|
||||
name: piece?.name ?? piece?.typePiece?.name ?? '',
|
||||
reference: piece?.reference ?? '',
|
||||
quantity: piece?.quantity ?? piece?.quantite ?? undefined,
|
||||
typePieceId: piece?.typePieceId ?? piece?.typePiece?.id ?? '',
|
||||
typePieceLabel: piece?.typePieceLabel ?? piece?.typePiece?.name ?? '',
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -254,9 +280,11 @@ const mapSubComponents = (components: any[]): any[] => {
|
||||
return []
|
||||
}
|
||||
return components.map((component) => ({
|
||||
name: component?.name ?? '',
|
||||
name: component?.name ?? component?.typeComposant?.name ?? '',
|
||||
description: component?.description ?? '',
|
||||
quantity: component?.quantity ?? component?.quantite ?? undefined,
|
||||
typeComposantId: component?.typeComposantId ?? component?.typeComposant?.id ?? '',
|
||||
typeComposantLabel: component?.typeComposantLabel ?? component?.typeComposant?.name ?? '',
|
||||
customFields: mapComponentCustomFields(component?.customFields),
|
||||
pieces: mapComponentPieces(component?.pieces),
|
||||
subComponents: mapSubComponents(component?.subComponents),
|
||||
|
||||
Reference in New Issue
Block a user