refactor: extract constants + mapper from NewListing.tsx (526 → 442 lines)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Sutter
2026-05-24 01:05:57 +02:00
parent 0bacd188d6
commit f0988b7250
3 changed files with 156 additions and 109 deletions
+78
View File
@@ -0,0 +1,78 @@
import { AssetType, AvailabilityStatus, ResultType } from '../../domain/enums'
import type { CreatePropertyInput } from '../../domain/property'
import { ASSET_TYPE_LABELS, LEVEL_TO_SCORE } from './newListingConstants'
export function buildCreatePropertyInput(fields: {
assetType: string
street: string
houseNumber: string
postalCode: string
city: string
areaSqm: number
rentPerSqm: number
availableFrom: string
description: string
softLevels: Record<string, string>
floor: string
fitOut: string
parking: string
ceilingHeight: string
images: string[]
}): CreatePropertyInput {
const {
assetType, street, houseNumber, postalCode, city,
areaSqm, rentPerSqm, availableFrom, description,
softLevels, floor, fitOut, parking, ceilingHeight, images,
} = fields
const sf = {
prestigeScore: LEVEL_TO_SCORE[softLevels.prestige ?? ''],
commuterAccessScore: LEVEL_TO_SCORE[softLevels.accessibility ?? ''],
visibilityScore: LEVEL_TO_SCORE[softLevels.visibility ?? ''],
footfallScore: LEVEL_TO_SCORE[softLevels.footfall ?? ''],
talentAccessScore: LEVEL_TO_SCORE[softLevels.talentAccess ?? ''],
esgScore: LEVEL_TO_SCORE[softLevels.esg ?? ''],
flexibilityScore: LEVEL_TO_SCORE[softLevels.flexibility ?? ''],
expansionPotentialScore: LEVEL_TO_SCORE[softLevels.expansionPotential ?? ''],
taxEnvironmentScore: LEVEL_TO_SCORE[softLevels.taxEnvironment ?? ''],
}
const hf = {
floor: floor ? parseInt(floor) : undefined,
fitOut: (fitOut || undefined) as 'SHELL' | 'BASIC' | 'FULL' | 'PREMIUM' | undefined,
parking: parking ? parseInt(parking) : undefined,
ceilingHeightM: ceilingHeight ? parseFloat(ceilingHeight) : undefined,
}
return {
title: `${ASSET_TYPE_LABELS[assetType] ?? assetType} · ${city}`,
assetType: assetType as typeof AssetType[keyof typeof AssetType],
resultType: ResultType.EXTERNAL_MARKET,
sourceType: 'DIRECT',
location: { city, country: 'CH' },
address: {
street: street.trim(),
houseNumber: houseNumber.trim(),
postalCode: postalCode.trim(),
city: city.trim(),
country: 'CH',
},
areaSqm,
rentPricePerSqm: rentPerSqm,
availabilityDate: availableFrom || new Date().toISOString().slice(0, 10),
availabilityStatus: availableFrom ? AvailabilityStatus.AVAILABLE_SOON : AvailabilityStatus.AVAILABLE_NOW,
confidenceScore: 1.0,
description: description.trim() || undefined,
softFactors: sf,
hardFacts: hf,
images: images.length > 0 ? images : undefined,
dataQuality: {
score: 1.0,
missingCriticalFields: [],
missingOptionalFields: [],
freshness: 'FRESH',
warnings: [],
},
status: 'ACTIVE',
}
}