From cd5b5e4c4e556821c5aa38f990a81c86636ea4a1 Mon Sep 17 00:00:00 2001 From: HotelSync Date: Thu, 26 Mar 2026 23:22:20 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20backend=20TS=20errors=20=E2=80=94=20agen?= =?UTF-8?q?t=20role=20type,=20WebSocket=20SocketStream,=20jwt.sign=20cast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- backend/src/agent-ws.ts | 6 ++++-- backend/src/routes/workstations.ts | 3 ++- backend/src/types.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/agent-ws.ts b/backend/src/agent-ws.ts index 0b08774..7531310 100644 --- a/backend/src/agent-ws.ts +++ b/backend/src/agent-ws.ts @@ -4,6 +4,7 @@ * и остаются подключёнными для получения команд */ import { FastifyInstance } from 'fastify' +import type { SocketStream } from '@fastify/websocket' import { WebSocket } from 'ws' import { db } from './db' @@ -71,7 +72,9 @@ async function markOnline(workstationId: string, ip?: string) { // Регистрируем route для WebSocket агентов export function setupAgentWsRoute(fastify: FastifyInstance) { - fastify.get('/ws/agent', { websocket: true }, async (socket: AgentSocket, req) => { + fastify.get('/ws/agent', { websocket: true }, async (connection: SocketStream, req) => { + const socket = connection.socket as AgentSocket + // Аутентификация по токену из заголовка try { const authHeader = req.headers.authorization ?? '' @@ -112,7 +115,6 @@ export function setupAgentWsRoute(fastify: FastifyInstance) { // Обрабатываем ответы агента (результаты команд) if (msg.type === 'result') { fastify.log.info({ workstation: wsId, result: msg }, 'Agent command result') - // TODO: можно эмитить в EventEmitter для ожидающих промисов } if (msg.type === 'hello') { console.log(`[agent-ws] Hello from ${msg.agent_id} (${wsId})`) diff --git a/backend/src/routes/workstations.ts b/backend/src/routes/workstations.ts index 6dd6fdd..78fbeec 100644 --- a/backend/src/routes/workstations.ts +++ b/backend/src/routes/workstations.ts @@ -173,7 +173,8 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => { ) // Выдаём токен агенту (подписываем как обычный JWT с role=agent) - const token = fastify.jwt.sign( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const token = (fastify.jwt.sign as any)( { sub: agent_id, role: 'agent', diff --git a/backend/src/types.ts b/backend/src/types.ts index 8b7d24b..01d8f7d 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -2,7 +2,7 @@ export interface JwtPayload { sub: string // user.id (UUID) email: string name: string - role: 'hotel_admin' | 'manager' | 'housekeeper' | 'super_admin' | 'receptionist' | 'accountant' | 'security' | 'technician' + role: 'hotel_admin' | 'manager' | 'housekeeper' | 'super_admin' | 'receptionist' | 'accountant' | 'security' | 'technician' | 'agent' hotelId: string | null hotelSlug: string | null }