Skip to content

Add pagination and ordering to NotificationsService.getNotifications #1016

Description

@RUKAYAT-CODER

Overview

NotificationsService.getNotifications(userId) executes this.notificationRepository.find({ where: { userId } }) — every notification ever created for that user, in unspecified order. Notifications are high-volume by nature and are never deleted by any code path in the module, so this grows without bound for active users. The absence of an order clause also means the result ordering is whatever the storage engine returns, so a client cannot rely on newest-first even before considering the volume.

Specifications

Features:

  • Notification retrieval is paginated and ordered newest-first.
  • Unread filtering is supported without a full scan.

Tasks:

  • Add PaginationQueryDto support with order: { createdAt: 'DESC' }, skip, and take, returning the standard paginated envelope.
  • Add an optional status / unread filter parameter.
  • Add a composite index on notification(userId, createdAt DESC).
  • Coordinate with the retention policy so old notifications are pruned rather than accumulating indefinitely.

Impacted Files:

  • src/notifications/notifications.service.ts
  • src/notifications/entities/notification.entity.ts

Acceptance Criteria

  • Notification listing returns a bounded page ordered newest-first.
  • Unread filtering uses an index rather than scanning.
  • The composite index exists via migration.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions