Skip to content

[BE-66] Implement WebSocket gateway for real-time asset events and live notifications #1036

Description

@yusuftomilola

Overview

The existing notification system dispatches records to the database, but there is no push mechanism to inform connected clients instantly. Users must refresh the page to see new notifications, asset status changes, or incoming maintenance alerts. This issue adds a WebSocket gateway to push events to clients in real time.

Context

  • @nestjs/websockets and socket.io are already installed (referenced in recent BullMQ PR)
  • The notification entity (from BE-53 or BE-54) is the source of truth — the gateway emits after a notification is persisted
  • Clients should authenticate the WebSocket connection using the same JWT access token used for HTTP

Acceptance Criteria

  • Create src/gateway/events.gateway.ts extending WebSocketGateway with CORS configured from ConfigService
  • On client connection: validate the JWT from the handshake query/header, reject unauthenticated connections with a WsException
  • Join the authenticated user to a private room keyed by user.id
  • Emit notification.new event when a notification is created for a user
  • Emit asset.status_changed event to the asset's department room when an asset status changes
  • Emit maintenance.due event when a maintenance job processor detects an upcoming due date
  • Create GatewayModule and register it in AppModule
  • Document the event schema for each emitted event in src/gateway/events.gateway.ts JSDoc

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions