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

@@ -119,6 +119,15 @@ const CHANNEL_DISPLAY_NAMES: Record<string, string> = {
onetwotrip: 'OneTwoTrip',
}
function normalizeRoom(r: Room): Room {
return {
...r,
baseRate: Number(r.baseRate) || 0,
hourlyRate: r.hourlyRate != null ? Number(r.hourlyRate) : undefined,
floor: Number(r.floor) || 0,
}
}
function normalizeChannel(raw: Record<string, unknown>): Channel {
const name = raw.name as ChannelName
return {
@@ -171,13 +180,13 @@ export const api = {
// ── Rooms ─────────────────────────────────────────────────────────────────
rooms: {
list: (slug: string) =>
req<Room[]>('GET', `/api/hotels/${slug}/rooms`),
req<Room[]>('GET', `/api/hotels/${slug}/rooms`).then(rooms => rooms.map(normalizeRoom)),
create: (slug: string, data: RoomPayload) =>
req<Room>('POST', `/api/hotels/${slug}/rooms`, toRoomPayload(data)),
req<Room>('POST', `/api/hotels/${slug}/rooms`, toRoomPayload(data)).then(normalizeRoom),
update: (slug: string, id: string, data: Partial<RoomPayload>) =>
req<Room>('PATCH', `/api/hotels/${slug}/rooms/${id}`, toRoomPayload(data)),
req<Room>('PATCH', `/api/hotels/${slug}/rooms/${id}`, toRoomPayload(data)).then(normalizeRoom),
delete: (slug: string, id: string) =>
req<void>('DELETE', `/api/hotels/${slug}/rooms/${id}`),