Fix reservation_id: numeric string via hex→decimal UUID conversion

This commit is contained in:
2026-03-19 12:40:52 +03:00
parent f5ade5cb53
commit 32115399ee

View File

@@ -318,7 +318,7 @@ const netup: FastifyPluginAsync = async (fastify) => {
if (!room) return reply.code(404).send({ error: 'Room not found' }) if (!room) return reply.code(404).send({ error: 'Room not found' })
const result = await notifyNetupCheckinInternal( const result = await notifyNetupCheckinInternal(
hotelId, room_id, room.number, 'Тестовый гость', 'TEST-' + room.number, hotelId, room_id, room.number, 'Тестовый гость', '99999999',
) )
if (result.ok) return { ok: true, message: `Check-in отправлен в NetUP (номер ${result.netupRoom})` } if (result.ok) return { ok: true, message: `Check-in отправлен в NetUP (номер ${result.netupRoom})` }
return reply.code(502).send({ error: result.error ?? 'Ошибка' }) return reply.code(502).send({ error: result.error ?? 'Ошибка' })
@@ -368,8 +368,10 @@ async function notifyNetupCheckinInternal(
const url = `${base}/mw/api/hotel-room/${encodeURIComponent(mapping.netup_room_number)}/check-in` const url = `${base}/mw/api/hotel-room/${encodeURIComponent(mapping.netup_room_number)}/check-in`
const cred = Buffer.from(`${cfg.username}:${cfg.password}`).toString('base64') const cred = Buffer.from(`${cfg.username}:${cfg.password}`).toString('base64')
// NetUP expects reservation_id as a string // NetUP expects reservation_id as a numeric string (parses with strconv.Atoi)
const requestBody = { reservation_id: reservationId, name: guestName, language: language ?? cfg.default_language } // Convert UUID to a stable numeric string by taking first 8 hex chars → decimal
const resIdStr = String(parseInt(reservationId.replace(/-/g, '').slice(0, 8), 16) % 100000000)
const requestBody = { reservation_id: resIdStr, name: guestName, language: language ?? cfg.default_language }
try { try {
const res = await fetch(url, { const res = await fetch(url, {