Skip to content

Refactor notification utilities and enhance organization admin email handling#775

Merged
aks30 merged 4 commits intodevelopfrom
role-req-email-fix
Jul 31, 2025
Merged

Refactor notification utilities and enhance organization admin email handling#775
aks30 merged 4 commits intodevelopfrom
role-req-email-fix

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Jul 31, 2025

Summary by CodeRabbit

  • New Features

    • Email notifications now use the correct portal URL based on the tenant domain for accepted role requests.
  • Bug Fixes

    • Improved error handling in notification template operations to ensure consistent error propagation.
    • Simplified and unified parameter naming for organization codes in notification functions.
  • Chores

    • Removed unused imports and debug statements for cleaner code.
    • Enhanced error logging for email notification failures.

@coderabbitai
Copy link

coderabbitai bot commented Jul 31, 2025

Walkthrough

The changes update error handling in notification template database queries, refactor notification utility functions to standardize parameter naming, and enhance the organization admin service to dynamically fetch tenant domains for email notifications. Several function signatures are updated to use organizationCode and tenantCode, and some logging and error handling improvements are made.

Changes

Cohort / File(s) Change Summary
Notification Template DB Queries
src/database/queries/notificationTemplate.js
Removed unused import. Changed error handling in all async functions to throw errors instead of returning them, ensuring exceptions propagate. No changes to function signatures or other logic.
Org Admin Service Enhancements
src/services/org-admin.js
Updated sendRoleRequestStatusEmail function signature to accept tenantCode. Now fetches tenant domain dynamically for accepted status emails. Updated related calls and improved logging. Removed debug statements.
Notification Utilities Refactor
src/utils/notification.js
Renamed parameter organization_code to organizationCode in function signatures and internals. Simplified template existence checks by removing empty object fallback. Updated function signatures accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant AdminService as Org Admin Service
    participant TenantDomain as Tenant Domain Queries
    participant NotificationUtils as Notification Utils
    participant EmailService as Email Service

    AdminService->>TenantDomain: findOne(tenantCode)
    TenantDomain-->>AdminService: domain
    AdminService->>NotificationUtils: sendEmailNotification({emailId, templateCode, variables, tenantCode, organizationCode})
    NotificationUtils->>EmailService: Send email with variables and templates
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

A rabbit hops with nimble feet,
Through code where changes clean and neat—
Errors now fly, not quietly caught,
Domains fetched fresh, not hardwired or fraught.
With names aligned and clutter swept,
This code is tidy, safely kept!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7858cda and 558e469.

📒 Files selected for processing (3)
  • src/database/queries/notificationTemplate.js (6 hunks)
  • src/services/org-admin.js (4 hunks)
  • src/utils/notification.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/database/queries/**

⚙️ CodeRabbit Configuration File

Review database queries for performance. Check for N+1 problems and ensure indexes can be used.

Files:

  • src/database/queries/notificationTemplate.js
src/services/**

⚙️ CodeRabbit Configuration File

This is core business logic. Please check for correctness, efficiency, and potential edge cases.

Files:

  • src/services/org-admin.js
🧬 Code Graph Analysis (1)
src/utils/notification.js (2)
src/database/queries/notificationTemplate.js (2)
  • templateData (43-46)
  • templateData (77-80)
src/services/notification.js (1)
  • notificationTemplateQueries (3-3)
🔇 Additional comments (7)
src/database/queries/notificationTemplate.js (1)

22-22: All notificationTemplateQueries calls are safely wrapped in try-catch

I verified that every use of notificationTemplateQueries (findOne, findOneEmailTemplate, getEmailHeader, getEmailFooter, updateTemplate, findAllNotificationTemplates) lives inside a surrounding try { … } catch { … } block, so any thrown errors will be caught and handled.

Key locations with proper error handling:

  • src/utils/notification.js (sendEmailNotification, sendSMSNotification)
  • src/services/notification.js (create, update, read, readAllNotificationTemplates)
  • src/services/userInvite.js (within the Promise executor)
  • src/services/organization.js (invite flows)
  • src/services/tenant.js (default-template initialization)
  • src/services/account.js (registration, OTP, change-password flows)

All callers will catch and handle thrown errors as intended.

src/services/org-admin.js (4)

26-26: LGTM! Good addition of tenant domain queries.

The import of tenantDomainQueries supports the new dynamic tenant domain lookup functionality.


614-614: LGTM! Function signature updated consistently.

The function signature change to include organizationCode and tenantCode parameters is correctly implemented and all call sites are updated consistently.

Also applies to: 380-385


620-632: Excellent improvement: Dynamic tenant domain lookup.

Replacing the hardcoded process.env.PORTAL_URL with dynamic tenant domain lookup is a significant improvement that makes the system more flexible and tenant-aware.


655-655: Good addition of error logging.

Adding console.error(error) improves debugging capabilities for notification failures.

src/utils/notification.js (2)

10-10: LGTM! Parameter naming standardized to camelCase.

Renaming organization_code to organizationCode improves consistency with JavaScript naming conventions and aligns with the updated service layer calls.

Also applies to: 54-54


14-23: LGTM! Simplified template existence checking.

The direct check for falsy templateData is cleaner than the previous fallback to empty object approach. This works well with the updated database queries that now properly throw errors for failures.

Also applies to: 58-66

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch role-req-email-fix

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai Refactor notification utilities and enhance organization admin email handling Jul 31, 2025
@aks30 aks30 merged commit 5596b7a into develop Jul 31, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 22, 2025
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.

2 participants