feat: COM-port support for workstation devices + agent UI fixes

- EquipmentPage: add COM-port connection type with port field (COM1, /dev/ttyUSB0)
- api.ts: add comPort field to WorkstationDevice type
- workstations route: pass com_port to INSERT/PATCH
- migration 042: extend connection check constraint to include 'com', add com_port column
- agent index.html: highlight first cell on load, reset input on unpair

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-27 12:41:31 +03:00
parent c5413566dd
commit b2b2034f4c
4 changed files with 51 additions and 19 deletions

View File

@@ -0,0 +1,13 @@
-- Добавляем поддержку COM-порта для устройств рабочего места
-- Расширяем CHECK constraint для connection (добавляем 'com')
ALTER TABLE workstation_devices
DROP CONSTRAINT IF EXISTS workstation_devices_connection_check;
ALTER TABLE workstation_devices
ADD CONSTRAINT workstation_devices_connection_check
CHECK (connection IN ('usb', 'network', 'com'));
-- Добавляем поле com_port (например: COM1, COM3, /dev/ttyUSB0)
ALTER TABLE workstation_devices
ADD COLUMN IF NOT EXISTS com_port VARCHAR(50);

View File

@@ -209,17 +209,17 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => {
// ── POST /api/hotels/:slug/workstations/:id/devices ─────────────────────────
fastify.post<WsParam & { Body: {
type: string; name: string; connection: string
network_host?: string; network_port?: number; purpose?: string; config?: object
network_host?: string; network_port?: number; com_port?: string; purpose?: string; config?: object
} }>(
'/api/hotels/:slug/workstations/:id/devices',
{ onRequest: [fastify.authenticate] },
async (req, reply) => {
const { id } = req.params
const { type, name, connection, network_host, network_port, purpose, config } = req.body
const { type, name, connection, network_host, network_port, com_port, purpose, config } = req.body
const { rows } = await db.query(
`INSERT INTO workstation_devices (workstation_id, type, name, connection, network_host, network_port, purpose, config)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING *`,
[id, type, name, connection, network_host ?? null, network_port ?? null, purpose ?? 'other', config ?? {}],
`INSERT INTO workstation_devices (workstation_id, type, name, connection, network_host, network_port, com_port, purpose, config)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) RETURNING *`,
[id, type, name, connection, network_host ?? null, network_port ?? null, com_port ?? null, purpose ?? 'other', config ?? {}],
)
return reply.code(201).send(rows[0])
},
@@ -232,7 +232,7 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => {
async (req, reply) => {
const { deviceId } = req.params
const body = req.body as Record<string, unknown>
const fields = ['name', 'connection', 'network_host', 'network_port', 'purpose', 'config']
const fields = ['name', 'connection', 'network_host', 'network_port', 'com_port', 'purpose', 'config']
const sets: string[] = []
const vals: unknown[] = []
fields.forEach(f => {