Menengah
19 Agustus 2026Temukan bug-nya: Node.js / NestJS
Satu potongan kode. Temukan bug-nya, atau buktikan tidak ada.
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}Klik baris yang menimbulkan masalah.
Keputusanmu
Satu percobaan per hari. Jawaban muncul langsung setelahnya.
Pertahankan rentetanmu
Buat akun untuk menjaga rentetanmu dan melacak kemajuanmu.