Skip to content

[BE-01] Implement WebSocket gateway for real-time notifications #1146

Description

@yusuftomilola

Overview

The notifications/gateway/notifications.gateway.ts file exists but is unimplemented — notifications are REST-poll-only. Members miss time-sensitive updates (booking confirmations, payment events) without a manual page refresh.

Context

  • NotificationType enum: backend/src/notifications/enums/notification-type.enum.ts
  • CreateNotificationProvider: backend/src/notifications/providers/create-notification.provider.ts — persists notifications via REST
  • Gateway file already scaffolded at: backend/src/notifications/gateway/notifications.gateway.ts
  • @nestjs/websockets and socket.io are available in the NestJS ecosystem

Tasks

  • Implement @WebSocketGateway() with CORS config in notifications.gateway.ts
  • handleConnection() authenticates the socket via JWT from the handshake Authorization header; disconnect unauthenticated sockets immediately
  • handleDisconnect() removes the socket from the user's room
  • Add notifyUser(userId, payload) method that emits to a user-specific room (e.g. room:${userId})
  • Call notifyUser() from CreateNotificationProvider after persisting each notification to the database
  • Register the gateway as a provider in NotificationsModule

Files to Modify / Create

  • backend/src/notifications/gateway/notifications.gateway.ts
  • backend/src/notifications/notifications.module.ts
  • backend/src/notifications/providers/create-notification.provider.ts

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions