fix: pagination and ordering to getNotifications (#1016) - #1404
Conversation
…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.
|
@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! 🚀 |
|
Well done on the job done so far! |
- merge duplicate @nestjs/swagger import in notifications.controller.ts - fix prettier whitespace in notifications.service.ts offset line
Sorry for the delay, there was error with "run lint". Fixed that already. |
|
Thee still lint errors |
- fix migration singlequote to satisfy prettier - add packages field to pnpm-workspace.yaml so pnpm 9.15.9 run lint works (was packages field missing)
Done |
|
Thank you for contributing to the project. |
You're welcome |
Overview
Fixes #1016 —
NotificationsService.getNotificationswas unbounded and unordered.Changes
PaginationQueryDtosupport withorder: { createdAt: 'DESC' },skip/takereturning standard paginated envelope viaPaginationService.paginatestatus/isReadfilter using indexedandWhere(avoids full scan)PaginationService.paginateto supportDESC(newest-first) with correct cursor operator<vs>NotificationsQueryDto extends PaginationQueryDtofor validated query paramsnotification(userId, createdAt DESC),(userId, isRead, createdAt),(userId, status, createdAt)1810000000000-add-notifications-pagination-indexes.tsVerification
tsc --noEmit --skipLibCheckpass (no errors for edited files)jest src/notifications/notifications.service.spec.tsPASSCloses #1016