Intermedio
19 agosto 2026Trova il bug: Node.js / NestJS
Uno snippet di codice. Trova il bug, o dimostra che non ce n'è.
typescript
1import { WebSocketGateway, SubscribeMessage, MessageBody, ConnectedSocket } from '@nestjs/websockets';
2import { Socket } from 'socket.io';
3import { MessagesService } from './messages.service';
4
5@WebSocketGateway({ namespace: 'chat' })
6export class ChatGateway {
7 constructor(private readonly messages: MessagesService) {}
8
9 @SubscribeMessage('joinRoom')
10 async joinRoom(
11 @ConnectedSocket() client: Socket,
12 @MessageBody() data: { roomId: string },
13 ) {
14 client.join(data.roomId);
15 const history = await this.messages.getRoomHistory(data.roomId);
16 client.emit('history', history);
17 }
18}Clicca sulle righe che causano il problema.
Il tuo verdetto
Un tentativo al giorno. La risposta appare subito dopo.
Mantieni la tua serie
Crea un account per conservare la tua serie e seguire i tuoi progressi.