diff --git a/backend/src/routes/ttlock.ts b/backend/src/routes/ttlock.ts index 3bc1f8f..52b8e33 100644 --- a/backend/src/routes/ttlock.ts +++ b/backend/src/routes/ttlock.ts @@ -64,10 +64,10 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { // ── PATCH /api/hotels/:slug/ttlock/config ─────────────────────────────────── fastify.patch('/api/hotels/:slug/ttlock/config', { onRequest: [fastify.authenticate] }, async (req, reply) => { const { slug } = req.params @@ -76,7 +76,7 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { const hotelId = await getHotelId(slug) if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' }) - const { isEnabled, clientId, clientSecret, cardSectors } = req.body + const { is_enabled: isEnabled, client_id: clientId, client_secret: clientSecret, card_sectors: cardSectors } = req.body await db.query( `INSERT INTO hotel_ttlock_config (hotel_id, is_enabled, client_id, client_secret, card_sectors) @@ -100,7 +100,7 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { // ── POST /api/hotels/:slug/ttlock/test ────────────────────────────────────── // Проверяем: агент онлайн, энкодер отвечает на COM-порту - fastify.post( + fastify.post( '/api/hotels/:slug/ttlock/test', { onRequest: [fastify.authenticate] }, async (req, reply) => { @@ -110,8 +110,8 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { const hotelId = await getHotelId(slug) if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' }) - const { workstationId } = req.body - if (!workstationId) return reply.code(400).send({ error: 'workstationId required' }) + const workstationId = req.body.workstation_id + if (!workstationId) return reply.code(400).send({ error: 'workstation_id required' }) const { rows: wsRows } = await db.query( 'SELECT ttlock_com_port FROM workstations WHERE id = $1 AND hotel_id = $2', @@ -163,7 +163,7 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { }) // ── POST /api/hotels/:slug/ttlock/room-locks ───────────────────────────────── - fastify.post( + fastify.post( '/api/hotels/:slug/ttlock/room-locks', { onRequest: [fastify.authenticate] }, async (req, reply) => { @@ -173,9 +173,9 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { const hotelId = await getHotelId(slug) if (!hotelId) return reply.code(404).send({ error: 'Hotel not found' }) - const { roomId, lockMac, lockName } = req.body + const { room_id: roomId, lock_mac: lockMac, lock_name: lockName } = req.body // Нормализуем MAC: убираем двоеточия, приводим к верхнему регистру - const mac = lockMac.replace(/:/g, '').toUpperCase() + const mac = (lockMac ?? '').replace(/:/g, '').toUpperCase() if (!/^[0-9A-F]{12}$/.test(mac)) { return reply.code(400).send({ error: 'MAC-адрес должен быть 12 HEX-символов (напр. 42A6BBF5ECE5)' }) } @@ -203,7 +203,7 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { }) // ── POST /api/hotels/:slug/bookings/:bookingId/issue-card ──────────────────── - fastify.post( + fastify.post( '/api/hotels/:slug/bookings/:bookingId/issue-card', { onRequest: [fastify.authenticate] }, async (req, reply) => { @@ -244,11 +244,11 @@ const ttlockRoutes: FastifyPluginAsync = async (fastify) => { let workstationId: string let comPort: string - if (req.body?.workstationId) { + if (req.body?.workstation_id) { // Явно указано рабочее место const { rows: wsRows } = await db.query( 'SELECT id, ttlock_com_port FROM workstations WHERE id = $1 AND hotel_id = $2', - [req.body.workstationId, hotelId], + [req.body.workstation_id, hotelId], ) const ws = wsRows[0] if (!ws || !ws.ttlock_com_port) {