Skip to content

fix: pagination and ordering to getNotifications (#1016) - #1404

Open
Sagethepeak wants to merge 3 commits into
rinafcode:mainfrom
Sagethepeak:fix/1016-notifications-pagination
Open

fix: pagination and ordering to getNotifications (#1016)#1404
Sagethepeak wants to merge 3 commits into
rinafcode:mainfrom
Sagethepeak:fix/1016-notifications-pagination

Conversation

@Sagethepeak

Copy link
Copy Markdown

Overview

Fixes #1016NotificationsService.getNotifications was unbounded and unordered.

Changes

  • Add PaginationQueryDto support with order: { createdAt: 'DESC' }, skip/take returning standard paginated envelope via PaginationService.paginate
  • Add optional status/isRead filter using indexed andWhere (avoids full scan)
  • Update PaginationService.paginate to support DESC (newest-first) with correct cursor operator < vs >
  • Add NotificationsQueryDto extends PaginationQueryDto for validated query params
  • Add composite indexes on notification(userId, createdAt DESC), (userId, isRead, createdAt), (userId, status, createdAt)
  • Add migration 1810000000000-add-notifications-pagination-indexes.ts

Verification

  • tsc --noEmit --skipLibCheck pass (no errors for edited files)
  • jest src/notifications/notifications.service.spec.ts PASS

Closes #1016

…inafcode#1016)

- paginate getNotifications with PaginationQueryDto (skip/take), order {createdAt: DESC} newest-first and standard paginated envelope
- add optional status/isRead filter using indexed where clauses (avoids full scan)
- update PaginationService.paginate to support DESC/ASC ordering and correct cursor operator (< vs >)
- delegate findForUser to getNotifications for single source of truth
- add composite indexes on notification(userId, createdAt DESC), (userId, isRead, createdAt), (userId, status, createdAt)
- add migration 1810000000000-add-notifications-pagination-indexes.ts
- expose pagination query params via NotificationsController with ApiQuery decorators

Closes rinafcode#1016
…d/status filters

Global ValidationPipe whitelist+forbidNonWhitelisted would reject isRead/status when controller used PaginationQueryDto intersection type. Introduce NotificationsQueryDto extends PaginationQueryDto with @Transform for string boolean coercion and @IsEnum for status.

Ensures GET /notifications?isRead=false&status=sent passes validation and uses indexes.
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@Sagethepeak Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass

- merge duplicate @nestjs/swagger import in notifications.controller.ts
- fix prettier whitespace in notifications.service.ts offset line
@Sagethepeak

Copy link
Copy Markdown
Author

Well done on the job done so far!
Kindly fix workflow to pass

Sorry for the delay, there was error with "run lint". Fixed that already.

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thee still lint errors
Run pnpn run lint to view and fix errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pagination and ordering to NotificationsService.getNotifications

2 participants