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 { FastifyInstance } from 'fastify'
|
||||||
|
import type { SocketStream } from '@fastify/websocket'
|
||||||
import { WebSocket } from 'ws'
|
import { WebSocket } from 'ws'
|
||||||
import { db } from './db'
|
import { db } from './db'
|
||||||
|
|
||||||
@@ -71,7 +72,9 @@ async function markOnline(workstationId: string, ip?: string) {
|
|||||||
|
|
||||||
// Регистрируем route для WebSocket агентов
|
// Регистрируем route для WebSocket агентов
|
||||||
export function setupAgentWsRoute(fastify: FastifyInstance) {
|
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 {
|
try {
|
||||||
const authHeader = req.headers.authorization ?? ''
|
const authHeader = req.headers.authorization ?? ''
|
||||||
@@ -112,7 +115,6 @@ export function setupAgentWsRoute(fastify: FastifyInstance) {
|
|||||||
// Обрабатываем ответы агента (результаты команд)
|
// Обрабатываем ответы агента (результаты команд)
|
||||||
if (msg.type === 'result') {
|
if (msg.type === 'result') {
|
||||||
fastify.log.info({ workstation: wsId, result: msg }, 'Agent command result')
|
fastify.log.info({ workstation: wsId, result: msg }, 'Agent command result')
|
||||||
// TODO: можно эмитить в EventEmitter для ожидающих промисов
|
|
||||||
}
|
}
|
||||||
if (msg.type === 'hello') {
|
if (msg.type === 'hello') {
|
||||||
console.log(`[agent-ws] Hello from ${msg.agent_id} (${wsId})`)
|
console.log(`[agent-ws] Hello from ${msg.agent_id} (${wsId})`)
|
||||||
|
|||||||
@@ -173,7 +173,8 @@ const workstationRoutes: FastifyPluginAsync = async (fastify) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Выдаём токен агенту (подписываем как обычный JWT с role=agent)
|
// Выдаём токен агенту (подписываем как обычный 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,
|
sub: agent_id,
|
||||||
role: 'agent',
|
role: 'agent',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ export interface JwtPayload {
|
|||||||
sub: string // user.id (UUID)
|
sub: string // user.id (UUID)
|
||||||
email: string
|
email: string
|
||||||
name: 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
|
hotelId: string | null
|
||||||
hotelSlug: string | null
|
hotelSlug: string | null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user