leave room
This commit is contained in:
@@ -54,3 +54,5 @@ pids
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
/react/*
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from '@nestjs/websockets';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { Logger, UseGuards, Inject, forwardRef } from '@nestjs/common';
|
||||
import { NotificationService } from './services/notification.service';
|
||||
import { NotificationService } from './services/notification.service';
|
||||
import { WsAdminAuthGuard, type AuthenticatedSocket } from './guards/ws-admin-auth.guard';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { ExecutionContext } from '@nestjs/common';
|
||||
@@ -52,6 +52,7 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
|
||||
handleDisconnect(client: Socket) {
|
||||
this.logger.log(`Client disconnected: ${client.id}`);
|
||||
this.handleLeaveRoom(client);
|
||||
}
|
||||
|
||||
sendInAppNotification(repipient: { adminId: string; restaurantId: string }, payload: IInAppNotificationPayload) {
|
||||
@@ -64,6 +65,13 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
private getRoom(adminId: string, restaurantId: string) {
|
||||
return `restaurant:${restaurantId}-admin:${adminId}`;
|
||||
}
|
||||
|
||||
handleLeaveRoom(client: AuthenticatedSocket) {
|
||||
const room = this.getRoom(client.adminId!, client.restId!);
|
||||
void client.leave(room);
|
||||
this.logger.log(`Admin ${client.adminId} (Client ${client.id}) left room: ${room}`);
|
||||
void client.emit('left', { room, message: 'Successfully Admin left room' });
|
||||
}
|
||||
/**
|
||||
* Join a room for a specific restaurant (admin/staff)
|
||||
* Requires admin authentication via JWT token
|
||||
@@ -273,7 +281,7 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
|
||||
const canActivate = await guard.canActivate(context);
|
||||
if (!canActivate) {
|
||||
throw new Error('Authentication failed');
|
||||
throw new Error('Authentication failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user