fix: hide NetUP server URL field in agent mode, derive from device config

- TvWelcomePage: hide server URL input when connection_type=agent
- Test button enabled in agent mode without serverUrl
- Backend test endpoint: derive server_url from workstation netup device
- getNetupCfg: resolve URL from netup device in agent mode

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 21:06:33 +03:00
parent 30257a6079
commit bf785b763f
2 changed files with 45 additions and 17 deletions

View File

@@ -188,10 +188,24 @@ const netup: FastifyPluginAsync = async (fastify) => {
[hotelId],
)
const cfg = rows[0]
if (!cfg?.server_url) return reply.code(400).send({ error: 'Настройки не заполнены' })
// В agent-режиме берём адрес из устройства netup на рабочем месте
let effectiveUrl = cfg?.server_url ?? ''
if (cfg?.connection_type === 'agent' && cfg?.agent_workstation_id) {
const { rows: [dev] } = await db.query(
`SELECT network_host, network_port FROM workstation_devices
WHERE workstation_id = $1 AND type = 'netup' ORDER BY id LIMIT 1`,
[cfg.agent_workstation_id],
)
if (dev?.network_host) {
effectiveUrl = `http://${dev.network_host}:${dev.network_port ?? 80}`
}
}
if (!effectiveUrl) return reply.code(400).send({ error: 'Настройки не заполнены' })
try {
const result = await netupReq(cfg, 'GET', '/hotel-room')
const result = await netupReq({ ...cfg, server_url: effectiveUrl }, 'GET', '/hotel-room')
if (result.ok) return { ok: true, message: 'Подключение успешно' }
return reply.code(502).send({ error: `NetUP вернул статус ${result.status}` })
} catch (err) {
@@ -433,6 +447,20 @@ async function getNetupCfg(hotelId: string, needEnabled = true) {
`SELECT server_url, username, password, default_language, connection_type, agent_workstation_id FROM netup_settings WHERE hotel_id = $1 ${cond}`,
[hotelId],
)
if (!cfg) return undefined
// В agent-режиме подставляем адрес из устройства netup на рабочем месте
if (cfg.connection_type === 'agent' && cfg.agent_workstation_id) {
const { rows: [dev] } = await db.query(
`SELECT network_host, network_port FROM workstation_devices
WHERE workstation_id = $1 AND type = 'netup' ORDER BY id LIMIT 1`,
[cfg.agent_workstation_id],
).catch(() => ({ rows: [] }))
if (dev?.network_host) {
cfg.server_url = `http://${dev.network_host}:${dev.network_port ?? 80}`
}
}
return cfg as { server_url: string; username: string; password: string; default_language: string; connection_type: string; agent_workstation_id: string | null } | undefined
}