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:
@@ -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
|
||||
})()
|
||||
|
||||
Reference in New Issue
Block a user