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