Skip to content
Snippets Groups Projects
Commit cf32a8a1 authored by L4168's avatar L4168
Browse files

add error for invalid notification socket message

parent bce14d94
No related branches found
No related tags found
2 merge requests!59Development to master,!54Development to testing
...@@ -50,12 +50,25 @@ export class NotificationGateway ...@@ -50,12 +50,25 @@ export class NotificationGateway
async handleMessage(client: Socket, data: NotificationdDTO) { async handleMessage(client: Socket, data: NotificationdDTO) {
// check if the game exists and is either started or paused // check if the game exists and is either started or paused
const game = await this.gameRepository.findOne({ id: data.game }); const game = await this.gameRepository.findOne({ id: data.game });
if (game && ['STARTED', 'PAUSED'].includes(game.state)) { if (!game) {
// inform user about error
this.server.to(client.id).emit(data.game, {
type: 'error',
message: 'Game was not found',
});
}
if (['STARTED', 'PAUSED'].includes(game.state)) {
// send the message to all clients listening to gameId branch // send the message to all clients listening to gameId branch
this.server.emit(data.game, data); this.server.emit(data.game, data);
// create entry for notification in db // create entry for notification in db
const message = await this.notificationRepository.create(data); const message = await this.notificationRepository.create(data);
await this.notificationRepository.insert(message); await this.notificationRepository.insert(message);
} else {
// inform user about error
this.server.to(client.id).emit(data.game, {
type: 'error',
message: 'Notifications can be sent only in STARTED and PAUSED state',
});
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment