refactor(model): split modelUtils.ts into 3 thematic modules (F5.1)
Split 1017 LOC monolith into: - shared/model/componentStructure.ts (~590 LOC) - shared/model/pieceProductStructure.ts (~155 LOC) - shared/model/definitionOverrides.ts (~50 LOC) Rewrite modelUtils.ts as 37 LOC barrel re-export for backward compat. All 11 consumer files unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
49
app/shared/model/definitionOverrides.ts
Normal file
49
app/shared/model/definitionOverrides.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { uniqueConstructeurIds } from '../constructeurUtils'
|
||||
|
||||
export interface DefinitionOverridePayload {
|
||||
name?: string
|
||||
reference?: string
|
||||
constructeurIds?: string[]
|
||||
prix?: number
|
||||
}
|
||||
|
||||
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 = parsed
|
||||
}
|
||||
}
|
||||
|
||||
return Object.keys(payload).length ? payload : null
|
||||
}
|
||||
Reference in New Issue
Block a user