You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: cap getNotifications limit at 100 and add comprehensive tests
- Fix Math.max -> Math.min bug in getNotifications limit calculation
- Add handler unit tests (src/routes/notifications/handlers.test.ts)
- Add policy unit tests (src/policies/notifications.test.ts)
- Fix and expand service tests for sort field/direction validation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add param middleware
* Updates from code review
* refactor: separate per-user notification state into NotificationUserStates table
The Notifications table previously stored viewedAt and archivedAt directly
on the notification row. Global notifications (userId=null) could not track
whether different users had independently viewed or archived them — a single
row cannot hold state for multiple users.
Changes:
- Migration: creates NotificationUserStates (notificationId, userId,
viewedAt, archivedAt, UNIQUE on notificationId+userId with FK cascades),
backfills existing per-user state, and drops viewedAt/archivedAt from
Notifications
- New model: NotificationUserState with belongsTo Notification+User
- Notification model: removed archivedAt/viewedAt/isInformational, added
hasMany(NotificationUserState, { as: 'userStates' })
- Service: updateNotification → updateNotificationState(notificationId,
userId, { viewedAt?, archivedAt? }) — upserts per-user state row;
getNotifications(userId, scopes, options) — LEFT JOINs state, filters
archived, returns NotificationWithState[]
- Types: added NotificationUserStateModel and NotificationWithState
- Policy: added isGlobalNotification(); canUpdateNotification() now allows
admin, owner, or global notification (any user can set their own state)
- Handlers: getNotificationsHandler passes userId as first arg;
updateNotificationHandler calls updateNotificationState
- Spec: updated to document new table, service signatures, cleanup logic
- Tests: 121/121 passing across 10 suites
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Update to remove findOrCreate
* Update seeder
* Define relation in both directions
* Update test
* Map scopes to types directly to prevent drift
* Updates from code review
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments