feat: terminate agent socket and send unpair on workstation delete
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user