mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 02:00:56 +00:00
fix: backoffice socket
This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { Passenger as PassengerTypes } from '@edr/types';
|
||||
|
||||
import { PrismaService } from '../../common/prisma.service';
|
||||
import { WsAuthService } from './ws-auth.service';
|
||||
|
||||
/**
|
||||
@@ -34,27 +33,24 @@ export class SupportGateway implements OnGatewayConnection {
|
||||
@WebSocketServer()
|
||||
private readonly server!: Server;
|
||||
|
||||
constructor(
|
||||
private readonly wsAuth: WsAuthService,
|
||||
private readonly prisma: PrismaService,
|
||||
) {}
|
||||
constructor(private readonly wsAuth: WsAuthService) {}
|
||||
|
||||
async handleConnection(socket: Socket): Promise<void> {
|
||||
const userId = await this.wsAuth.resolveUserId(this.extractToken(socket));
|
||||
|
||||
// Authenticated: passenger (own room) or backoffice staff (shared room).
|
||||
// A valid token means a backoffice agent: the portal connects only with a
|
||||
// device/guest id (never a token), so every token-authed socket is staff.
|
||||
// Join the shared backoffice room — no passenger-row heuristic needed.
|
||||
if (userId) {
|
||||
socket.data.userId = userId;
|
||||
const passenger = await this.prisma.passenger.findUnique({
|
||||
where: { iamUserId: userId },
|
||||
socket.data.side = 'AGENT';
|
||||
await socket.join(SupportGateway.BACKOFFICE_ROOM);
|
||||
socket.emit('support:hello', {
|
||||
side: 'AGENT',
|
||||
room: SupportGateway.BACKOFFICE_ROOM,
|
||||
userId,
|
||||
});
|
||||
if (passenger) {
|
||||
await socket.join(`user:${userId}`);
|
||||
socket.data.side = 'USER';
|
||||
} else {
|
||||
await socket.join(SupportGateway.BACKOFFICE_ROOM);
|
||||
socket.data.side = 'AGENT';
|
||||
}
|
||||
this.logger.debug(`support socket ${socket.id} → AGENT (backoffice)`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user