Skip to content

[TTAHUB-5539] Specification for actionable notification backend#3661

Merged
thewatermethod merged 23 commits into
mainfrom
mb/TTAHUB-5539/actionable-notification-spec
Jun 9, 2026
Merged

[TTAHUB-5539] Specification for actionable notification backend#3661
thewatermethod merged 23 commits into
mainfrom
mb/TTAHUB-5539/actionable-notification-spec

Conversation

@thewatermethod

Copy link
Copy Markdown
Collaborator

Description of change

Design backend for actionable notifications. Frontend tickets are briefly listed but work will be broken down separately.

How to test

Review implementation proposal. Identify additional work that may need to be completed. Ask questions where specification is unclear.

Issue(s)

Checklists

Every PR

  • Meets issue criteria
  • JIRA ticket status updated
  • Code is meaningfully tested
  • Meets accessibility standards (WCAG 2.1 Levels A, AA)
  • API Documentation updated
  • Boundary diagram updated
  • Logical Data Model updated
  • Architectural Decision Records written for major infrastructure decisions
  • UI review complete
  • QA review complete

Before merge to main

  • OHS demo complete
  • Ready to create production PR

Production Deploy

  • PR created as Draft
  • Staging smoke test completed
  • PR transitioned to Open (this ready_for_review transition triggers the Slack/Jira automation)
  • Reviewer added after the PR is Open (elainaparrish is the authorized approver under normal circumstances)
    • Sequence: Draft PR → Smoke test → Open PR (automation runs) → Add reviewer
    • Confirm that the Slack notification was sent after the PR was opened
    • Confirm that linked Jira ticket(s) transitioned as expected; if not, review the GitHub Actions workflow logs

After merge/deploy

  • Update JIRA ticket status

@thewatermethod thewatermethod marked this pull request as ready for review May 29, 2026 18:41
Copilot AI review requested due to automatic review settings May 29, 2026 18:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a backend design specification for actionable notifications, outlining proposed data modeling, services, scopes, handlers, scheduled cleanup, email-notification simplification, and related frontend follow-up work.

Changes:

  • Adds a new specs/actionable-notifications/index.md design document.
  • Defines proposed notification schema, configuration, service APIs, scopes, and handler responsibilities.
  • Lists planned backend tickets plus frontend follow-up areas.

Impact Assessment:

  • Benefits: Medium — provides a shared implementation plan for a cross-cutting notification system.
  • Risks: Medium — unresolved schema and cleanup-query issues could lead to implementation mistakes if copied directly.

Comment thread specs/actionable-notifications/index.md Outdated
Comment thread specs/actionable-notifications/index.md Outdated
thewatermethod and others added 2 commits June 1, 2026 09:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@thewatermethod thewatermethod changed the title [TTAHUB-5539] Add specification for actionable notification backend [TTAHUB-5539] Specification for actionable notification backend Jun 1, 2026
Comment thread specs/actionable-notifications/index.md
Comment thread specs/actionable-notifications/index.md Outdated
Comment thread specs/actionable-notifications/index.md Outdated

@AdamAdHocTeam AdamAdHocTeam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. Should we mention something about cleaning up no longer valid notifications. For example two approvers added to report and submitted. Then the report is moved back to needs action?

Overall good start (minor comments)

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

⚠️ Diff size advisory: This PR is 3525 lines (3460+, 65−), exceeding the 500-line guideline. Consider splitting into smaller changes.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

⚠️ Review count advisory: 1 of 2 required human approvals. 1 more needed. Current approvers: AdamAdHocTeam.

@thewatermethod

Copy link
Copy Markdown
Collaborator Author

I think this looks good. Should we mention something about cleaning up no longer valid notifications. For example two approvers added to report and submitted. Then the report is moved back to needs action?

@AdamAdHocTeam good call, I updated to add a new service type

@kryswisnaskas kryswisnaskas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding four inline review findings from Codex.

Comment thread specs/actionable-notifications/index.md
Comment thread specs/actionable-notifications/index.md
Comment thread specs/actionable-notifications/index.md Outdated
Comment thread specs/actionable-notifications/index.md
thewatermethod and others added 11 commits June 4, 2026 13:49
* feat: add Notifications schema (model, migrations, seed, tests)

- Add NOTIFICATION_TYPES and actionable_notifications feature flag to constants
- Create Notifications table migration with all spec columns including archivedAt/viewedAt (DATEONLY)
- Add actionable_notifications to enum_Users_flags migration
- Create Notification Sequelize model with User association
- Add User.hasMany(Notification) association
- Add seed data with user-specific and global notifications
- Add model tests (8 passing)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Simplify model

* Update to add "triggeredAt" to model

* Add all enum types

* Remove digest from notifications enum

* Update model with other needed field

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: add Notifications schema (model, migrations, seed, tests)

- Add NOTIFICATION_TYPES and actionable_notifications feature flag to constants
- Create Notifications table migration with all spec columns including archivedAt/viewedAt (DATEONLY)
- Add actionable_notifications to enum_Users_flags migration
- Create Notification Sequelize model with User association
- Add User.hasMany(Notification) association
- Add seed data with user-specific and global notifications
- Add model tests (8 passing)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Simplify model

* Update to add "triggeredAt" to model

* Add all enum types

* Scopes, work in progress

* Remove digest from notifications enum

* Add notification scopes

* Register scopes

* Fix bugs, add integration test

* Update model with other needed field

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: add Notifications schema (model, migrations, seed, tests)

- Add NOTIFICATION_TYPES and actionable_notifications feature flag to constants
- Create Notifications table migration with all spec columns including archivedAt/viewedAt (DATEONLY)
- Add actionable_notifications to enum_Users_flags migration
- Create Notification Sequelize model with User association
- Add User.hasMany(Notification) association
- Add seed data with user-specific and global notifications
- Add model tests (8 passing)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Simplify model

* Update to add "triggeredAt" to model

* Add all enum types

* Scopes, work in progress

* Remove digest from notifications enum

* Add notification scopes

* Register scopes

* Fix bugs, add integration test

* Add services and tests

* Update model with other needed field

* Accomodate missing column in services

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Add notification configuration tests

* fix: replace generic deleteNotification(scopes) with targeted delete helpers

- deleteNotification(notificationId) now accepts a single ID, throws when
  falsy — eliminates the empty-scopes full-table-delete risk
- adds deleteNotificationsByEntityAndType(entityId, notificationType) for
  event-driven stale-notification cleanup; throws when either arg is falsy
- updates and expands tests to cover both new signatures and their guards
- updates spec doc with typed signatures and safety-guard notes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix bad test

* [TTAHUB-5387] Add notification handlers (#3674)

* 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>

* Regenerate Logical Data Model

* Condense down notifications table

* Remove extraneous migration

* Fix LDM bugs

* Remove extra columns from migration

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@thewatermethod thewatermethod enabled auto-merge June 9, 2026 14:30
@thewatermethod thewatermethod added this pull request to the merge queue Jun 9, 2026
Merged via the queue into main with commit 68aa759 Jun 9, 2026
14 checks passed
@thewatermethod thewatermethod deleted the mb/TTAHUB-5539/actionable-notification-spec branch June 9, 2026 15:55
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

📊 Review Metrics

Auto-generated by the PR Review Metrics workflow. Observe-only — no action required.

Metric Value
PR Status ✅ Merged
Reviewer Count 2
Reviewers @AdamAdHocTeam, @kryswisnaskas
First-Review Turnaround 68.7 hr
Total Review Events 7

Review Timeline

State Reviewer Submitted At
💬 COMMENTED @AdamAdHocTeam 2026-06-01 15:22 UTC
💬 COMMENTED @AdamAdHocTeam 2026-06-01 15:23 UTC
💬 COMMENTED @AdamAdHocTeam 2026-06-01 15:51 UTC
✅ APPROVED @AdamAdHocTeam 2026-06-01 15:52 UTC
💬 COMMENTED @AdamAdHocTeam 2026-06-01 15:53 UTC
💬 COMMENTED @kryswisnaskas 2026-06-03 15:19 UTC
💬 COMMENTED @kryswisnaskas 2026-06-03 16:16 UTC

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.

4 participants