Merges the full git history of Inventory_frontend into the monorepo under frontend/. Removes the submodule in favor of a unified repo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { uniqueConstructeurIds } from '../constructeurUtils'
|
|
|
|
export interface DefinitionOverridePayload {
|
|
name?: string
|
|
reference?: string
|
|
constructeurIds?: string[]
|
|
prix?: string
|
|
}
|
|
|
|
export const sanitizeDefinitionOverrides = (definition: any): DefinitionOverridePayload | null => {
|
|
if (!definition || typeof definition !== 'object') {
|
|
return null
|
|
}
|
|
|
|
const payload: DefinitionOverridePayload = {}
|
|
|
|
if (typeof definition.name === 'string') {
|
|
const name = definition.name.trim()
|
|
if (name.length > 0) {
|
|
payload.name = name
|
|
}
|
|
}
|
|
|
|
if (typeof definition.reference === 'string') {
|
|
const reference = definition.reference.trim()
|
|
if (reference.length > 0) {
|
|
payload.reference = reference
|
|
}
|
|
}
|
|
|
|
const constructeurIds = uniqueConstructeurIds(
|
|
definition.constructeurIds,
|
|
definition.constructeurId,
|
|
definition.constructeur,
|
|
definition.constructeurs,
|
|
)
|
|
if (constructeurIds.length) {
|
|
payload.constructeurIds = constructeurIds
|
|
}
|
|
|
|
if (definition.prix !== undefined && definition.prix !== null && definition.prix !== '') {
|
|
const parsed = Number(definition.prix)
|
|
if (!Number.isNaN(parsed)) {
|
|
payload.prix = String(parsed)
|
|
}
|
|
}
|
|
|
|
return Object.keys(payload).length ? payload : null
|
|
}
|