fix: backend TS errors — agent role type, WebSocket SocketStream, jwt.sign cast
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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})`)
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user