fix: normalizeRoom converts NUMERIC baseRate string to number in api.ts

PostgreSQL NUMERIC columns are returned as strings by node-postgres.
Added normalizeRoom() that coerces baseRate/hourlyRate/floor to JS numbers
before they reach components, eliminating string concatenation bugs like
"300005000.005000.00" in price calculations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 22:48:51 +03:00
parent 9af11df1b0
commit b631a281d2
2 changed files with 16 additions and 6 deletions

View File

@@ -337,13 +337,14 @@ export function BookingModal({ open, draft, rooms, bookings = [], onClose, onSav
if (!room || !form.checkIn || nightCount <= 0) return 0
const catId = room.categoryId
const catOverrides = catId ? priceOverrides?.[catId] : undefined
const fallback = room.baseRate ?? 0
// room.baseRate is NUMERIC in DB — pg returns it as a string; always coerce
const fallback = Number(room.baseRate) || 0
if (!catOverrides) return fallback * nightCount
let sum = 0
for (let i = 0; i < nightCount; i++) {
const d = format(addDays(parseISO(form.checkIn), i), 'yyyy-MM-dd')
const p = catOverrides[d]
sum += (typeof p === 'number' && isFinite(p)) ? p : fallback
const p = Number(catOverrides[d])
sum += (isFinite(p) && p > 0) ? p : fallback
}
return sum
})()