Skip to content

Updated project files#164

Open
Malcolm-Wander wants to merge 2 commits into
DelegoLabs:mainfrom
Malcolm-Wander:main
Open

Updated project files#164
Malcolm-Wander wants to merge 2 commits into
DelegoLabs:mainfrom
Malcolm-Wander:main

Conversation

@Malcolm-Wander

@Malcolm-Wander Malcolm-Wander commented Jun 24, 2026

Copy link
Copy Markdown

Changes made
Closed #135

Summary

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

Test plan

  • pnpm typecheck
  • pnpm test
  • Manual testing (describe):

Checklist

  • Follows project code conventions
  • TODOs reference issues where applicable
  • No secrets or credentials committed

Summary by CodeRabbit

  • New Features

    • Added database-backed notification preferences with separate email and push settings (with created/updated timestamps).
    • Notifications service now establishes a database connection during startup before serving requests.
    • Introduced a new notification_preferences table to persist per-user preference defaults.
  • Bug Fixes

    • Users without saved preferences now receive sensible defaults with both channels enabled.
    • Preference updates now reliably persist, including partial updates (missing values default to enabled).

@drips-wave

drips-wave Bot commented Jun 24, 2026

Copy link
Copy Markdown

@Malcolm-Wander 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

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Notifications now includes Sequelize/Postgres setup, service startup database authentication, a notification_preferences table/model, and helper functions to read or upsert per-user email and push preferences.

Changes

Notification preferences storage

Layer / File(s) Summary
Database foundation
apps/backend/notifications/package.json, apps/backend/notifications/src/db.ts
pg, pg-hstore, and sequelize are added, and the notifications service initializes a Sequelize Postgres client with pool, naming, logging, and authentication settings.
Preference schema
database/migrations/004_notification_preferences.sql, apps/backend/notifications/src/models/NotificationPreferences.ts
A notification_preferences table and matching Sequelize model are added with user_id, email_enabled, push_enabled, and timestamp fields.
Preference helpers
apps/backend/notifications/src/notificationPreferences.ts
Helper functions read preferences by user ID and upsert channel settings while defaulting omitted values to enabled.
Startup wiring
apps/backend/notifications/src/index.ts
The notifications service imports connectDb() and awaits database authentication during startup before the HTTP server starts.

Sequence Diagram(s)

sequenceDiagram
  participant NotificationsService
  participant Sequelize
  participant PostgresDatabase
  participant HttpServer
  NotificationsService->>Sequelize: connectDb()
  Sequelize->>PostgresDatabase: authenticate()
  PostgresDatabase-->>Sequelize: connection result
  Sequelize-->>NotificationsService: success or error
  NotificationsService->>HttpServer: start after connection
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A bunny hopped through code at dawn,
With email and push now neatly drawn.
The burrow hums, the DB purrs,
Two tiny prefs in cozy fur.
🐇✨ All set for hops both near and far.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The migration, model, and helper address #135, but tests and nearby documentation required by the issue are not shown. Add tests for lookup/default behavior and document any new migration, env var, or event shape near the notifications service or contract.
Title check ❓ Inconclusive The title is generic and does not describe the notification preference work. Rename it to something specific like "Add notification preferences model and migration".
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Out of Scope Changes check ✅ Passed The changes stay within the notifications service and migration scope, and the dependency updates support the new DB layer.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
apps/backend/notifications/src/index.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.12][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

apps/backend/notifications/package.json

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/backend/notifications/src/db.ts`:
- Line 6: The databaseUrl fallback in db.ts currently masks missing
configuration by silently connecting to a local Postgres instance with embedded
credentials. Update the DATABASE_URL handling in the db.ts initialization so the
fallback is only allowed for local development/test, and make it fail fast in
deployed/non-local environments when DATABASE_URL is absent. Use the existing
databaseUrl constant and the surrounding db connection setup as the place to
enforce this, and document that DATABASE_URL is now required outside local dev.
- Around line 12-13: Validate the Sequelize pool settings in db.ts before
building the config: read DATABASE_POOL_MIN and DATABASE_POOL_MAX, reject blank
strings, NaN, negative values, and any case where the parsed min is greater than
max, then fail fast at startup with a clear error message. Update the config
construction around the pool settings so Sequelize only receives validated
numeric values, and keep the check close to the existing pool config symbols
`min` and `max` for easy location.

In `@apps/backend/notifications/src/notificationPreferences.ts`:
- Around line 23-39: The upsertUserPreferences function is overwriting omitted
channels with defaults instead of preserving existing settings. Update this
function to load the current NotificationPreferences row for the given userId,
merge the incoming Partial<ChannelPreferences> with the existing values, and
then upsert the combined result so partial updates only change specified fields.
Keep the final return shape based on the saved record and use the existing
upsertUserPreferences and NotificationPreferences symbols to make the change
easy to locate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d30c7564-b2dd-4891-89d2-f82f5c7f28ff

📥 Commits

Reviewing files that changed from the base of the PR and between b3d63c6 and edfd6b2.

📒 Files selected for processing (6)
  • apps/backend/notifications/package.json
  • apps/backend/notifications/src/db.ts
  • apps/backend/notifications/src/index.ts
  • apps/backend/notifications/src/models/NotificationPreferences.ts
  • apps/backend/notifications/src/notificationPreferences.ts
  • database/migrations/004_notification_preferences.sql

Comment thread apps/backend/notifications/src/db.ts
Comment thread apps/backend/notifications/src/db.ts
Comment thread apps/backend/notifications/src/notificationPreferences.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/backend/notifications/package.json`:
- Around line 28-34: The devDependencies block in package.json has a duplicate
`@types/ws` entry with conflicting versions, so remove one of the entries and keep
a single consistent `@types/ws` declaration. Make sure the remaining dependency
version is the one intended for the notifications package, and verify the
manifest is valid with no repeated keys.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5db8ac10-e763-45f6-ad00-f6c07023a204

📥 Commits

Reviewing files that changed from the base of the PR and between edfd6b2 and 14be93b.

📒 Files selected for processing (2)
  • apps/backend/notifications/package.json
  • apps/backend/notifications/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/backend/notifications/src/index.ts

Comment on lines 28 to 34
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^22.0.0",
"@types/validator": "^13.15.10",
"@types/ws": "^8.18.1",
"@types/web-push": "^3.6.4",
"@types/ws": "^8.5.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Remove the duplicate @types/ws entry.

package.json declares @types/ws twice with different versions. That makes dependency resolution ambiguous, and many tools will either reject the manifest or silently keep only the last value.

Suggested fix
   "devDependencies": {
     "`@types/jsonwebtoken`": "^9.0.10",
     "`@types/node`": "^22.0.0",
     "`@types/validator`": "^13.15.10",
     "`@types/ws`": "^8.18.1",
     "`@types/web-push`": "^3.6.4",
-    "`@types/ws`": "^8.5.0",
     "tsx": "^4.19.0",
     "typescript": "^5.7.0",
     "vitest": "^2.1.9"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^22.0.0",
"@types/validator": "^13.15.10",
"@types/ws": "^8.18.1",
"@types/web-push": "^3.6.4",
"@types/ws": "^8.5.0",
"devDependencies": {
"`@types/jsonwebtoken`": "^9.0.10",
"`@types/node`": "^22.0.0",
"`@types/validator`": "^13.15.10",
"`@types/ws`": "^8.18.1",
"`@types/web-push`": "^3.6.4",
🧰 Tools
🪛 Biome (2.5.0)

[error] 32-32: The key @types/ws was already declared.

(lint/suspicious/noDuplicateObjectKeys)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/backend/notifications/package.json` around lines 28 - 34, The
devDependencies block in package.json has a duplicate `@types/ws` entry with
conflicting versions, so remove one of the entries and keep a single consistent
`@types/ws` declaration. Make sure the remaining dependency version is the one
intended for the notifications package, and verify the manifest is valid with no
repeated keys.

Source: Linters/SAST tools

@ScriptedBro

Copy link
Copy Markdown
Contributor

Resolve the conflicts

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.

[Notifications] Add Notification Preference Model

2 participants