251123:0200 T6.1 to DO

This commit is contained in:
2025-11-23 02:23:38 +07:00
parent 17d9f172d4
commit 23006898d9
58 changed files with 3221 additions and 502 deletions

View File

@@ -0,0 +1,38 @@
import {
WebSocketGateway,
WebSocketServer,
OnGatewayConnection,
OnGatewayDisconnect,
} from '@nestjs/websockets';
import { Server, Socket } from 'socket.io';
import { Logger } from '@nestjs/common';
@WebSocketGateway({
cors: {
origin: '*',
},
namespace: 'notifications',
})
export class NotificationGateway
implements OnGatewayConnection, OnGatewayDisconnect
{
@WebSocketServer()
server!: Server; // ✅ FIX: เติม ! (Definite Assignment Assertion)
private readonly logger = new Logger(NotificationGateway.name);
handleConnection(client: Socket) {
this.logger.log(`Client connected: ${client.id}`);
}
handleDisconnect(client: Socket) {
this.logger.log(`Client disconnected: ${client.id}`);
}
/**
* ส่งแจ้งเตือนไปหา User แบบ Real-time
*/
sendToUser(userId: number, payload: any) {
this.server.to(`user_${userId}`).emit('new_notification', payload);
}
}