Skip to content

[BE-55] Implement WebSocket notifications gateway for real-time in-app alerts #928

Description

@yusuftomilola

Overview

The frontend uses [email protected] for real-time communication. In-app notifications (asset transferred to you, work order assigned, maintenance due) must arrive instantly without page refresh. The WebSocket gateway was previously implemented and then deleted in commit be0be8c — it needs to be rebuilt.

Context

  • package.json has @nestjs/[email protected], @nestjs/[email protected], and [email protected]
  • The gateway must authenticate the WebSocket connection using the JWT from the handshake auth header
  • Each connected user joins a room named user:{userId} so notifications can be sent to specific users

Acceptance Criteria

  • Create NotificationsGateway with @WebSocketGateway({ cors: true, namespace: '/notifications' })
  • On handleConnection: extract JWT from client.handshake.auth.token, verify with JwtService, join room user:{userId}, disconnect unauthenticated clients
  • Create NotificationsService.sendToUser(userId, type, payload) — emits to the user's room: this.server.to(user:${userId}).emit('notification', { type, payload, timestamp })
  • Define notification types: ASSET_TRANSFERRED, WORK_ORDER_ASSIGNED, MAINTENANCE_DUE, BOOKING_CONFIRMED, CHECKOUT_OVERDUE, WARRANTY_EXPIRING
  • Create Notification entity to persist all sent notifications: id, userId, type, title, body, payload (JSON), isRead, createdAt
  • GET /notifications — current user's notification history, unread first
  • PATCH /notifications/:id/read and PATCH /notifications/read-all

Metadata

Metadata

Assignees

Labels

Type

No type
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