diff --git a/backend/src/routes/workstations.ts b/backend/src/routes/workstations.ts index d177871..7f16aa9 100644 --- a/backend/src/routes/workstations.ts +++ b/backend/src/routes/workstations.ts @@ -16,7 +16,7 @@ import { FastifyPluginAsync } from 'fastify' import { db } from '../db' import crypto from 'crypto' -import { sendCommand, sendCommandAndWait } from '../agent-ws' +import { sendCommand, sendCommandAndWait, getAgentSocket } from '../agent-ws' type SlugParam = { Params: { slug: string } } type WsParam = { Params: { slug: string; id: string } } @@ -106,6 +106,13 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => { if (!canManage(req.user.hotelSlug, req.user.role, slug)) return reply.code(403).send({ error: 'Forbidden' }) + // Notify agent to unpair, then terminate the socket + const socket = getAgentSocket(id) + if (socket) { + try { socket.send(JSON.stringify({ type: 'unpair' })) } catch { /* ignore */ } + setTimeout(() => socket.terminate(), 500) + } + await db.query('DELETE FROM workstations WHERE id = $1', [id]) return reply.code(204).send() },