Skip to content

Conversation

@nevil-mathew
Copy link
Collaborator

@nevil-mathew nevil-mathew commented Aug 4, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Updated the user-facing message for non-existent users to "User does not exist."
    • Improved accuracy when accepting terms and conditions by identifying users with tenant code instead of organization ID.
    • Enhanced reliability of user updates and error handling during terms and conditions acceptance.

@coderabbitai
Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

The changes update the handling of user acceptance of terms and conditions by switching from using organization_id to tenant_code as an identifier throughout the relevant controller and service logic. Additionally, a localization string for a user-not-found error message was updated to a more direct statement.

Changes

Cohort / File(s) Change Summary
Controller: Accept Terms and Conditions
src/controllers/v1/account.js
Changed argument in the acceptTermsAndCondition controller from organization_id to tenant_code.
Service: Accept Terms and Conditions Logic
src/services/account.js
Updated method signature and logic to use tenantCode instead of orgId; adjusted update and cache logic.
Localization Update
src/locales/en.json
Modified "USER_DOESNOT_EXISTS" string to a more direct user-not-found message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A hop, a skip, a tenant code swap,
Now terms are accepted with a brand new prop.
Redis keys pruned, caches swept clean,
Error messages sharper, more direct and keen.
With every tweak, this rabbit grins—
For tidy code is where joy begins! 🐇✨


📜 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 8116b44 and 1306701.

📒 Files selected for processing (3)
  • src/controllers/v1/account.js (1 hunks)
  • src/locales/en.json (1 hunks)
  • src/services/account.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/controllers/**

⚙️ CodeRabbit Configuration File

These are API controllers. Focus on request/response handling, security (auth middleware usage), and proper status codes.

Files:

  • src/controllers/v1/account.js
src/services/**

⚙️ CodeRabbit Configuration File

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

Files:

  • src/services/account.js
🧠 Learnings (3)
📓 Common learnings
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#776
File: src/database/models/entityType.js:38-38
Timestamp: 2025-07-31T08:43:35.971Z
Learning: The migration for converting tenant_code to a primary key in the EntityType model was already handled in a previous PR, not in the current refactoring PR that focuses on organization codes instead of organization IDs.
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#776
File: src/services/entities.js:18-23
Timestamp: 2025-07-31T08:44:36.982Z
Learning: In the ELEVATE-Project/user codebase, organizationCode and tenantCode parameters passed to service methods always come from req.decodedToken.organization_code and req.decodedToken.tenant_code, which are guaranteed to be present after token validation. Additional validation for these parameters in service methods is unnecessary as the token validation process ensures they are always available.
📚 Learning: in the elevate-project/user codebase, organizationcode and tenantcode parameters passed to service m...
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#776
File: src/services/entities.js:18-23
Timestamp: 2025-07-31T08:44:36.982Z
Learning: In the ELEVATE-Project/user codebase, organizationCode and tenantCode parameters passed to service methods always come from req.decodedToken.organization_code and req.decodedToken.tenant_code, which are guaranteed to be present after token validation. Additional validation for these parameters in service methods is unnecessary as the token validation process ensures they are always available.

Applied to files:

  • src/controllers/v1/account.js
  • src/services/account.js
📚 Learning: the migration for converting tenant_code to a primary key in the entitytype model was already handle...
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#776
File: src/database/models/entityType.js:38-38
Timestamp: 2025-07-31T08:43:35.971Z
Learning: The migration for converting tenant_code to a primary key in the EntityType model was already handled in a previous PR, not in the current refactoring PR that focuses on organization codes instead of organization IDs.

Applied to files:

  • src/controllers/v1/account.js
  • src/services/account.js
🔇 Additional comments (6)
src/services/account.js (4)

1677-1685: LGTM: JSDoc updated correctly

The documentation accurately reflects the new method signature and parameter types.


1686-1691: LGTM: Efficient direct update implementation

The method signature change from orgId to tenantCode aligns with the refactoring objectives. Using a direct update with composite key {id: userId, tenant_code: tenantCode} is more efficient than the previous fetch-then-update pattern and ensures proper tenant isolation.


1693-1699: LGTM: Proper affected rows validation

The condition correctly checks if no rows were affected by the update operation, indicating the user doesn't exist with the given composite key.


1701-1705: LGTM: Improved Redis cache management

The asynchronous Redis deletion with error logging is a good improvement that prevents blocking the response while ensuring cache consistency. The Redis key format ${common.redisUserPrefix}${tenantCode}_${userId} correctly incorporates the tenant code.

src/locales/en.json (1)

5-5: LGTM: More accurate error message

The updated message "User does not exist." is clearer and more accurate than the previous "Please enter correct email ID." This change aligns well with the service layer updates that now verify user existence using composite keys and supports multiple identifier types.

src/controllers/v1/account.js (1)

187-187: LGTM: Consistent parameter update

The change from req.decodedToken.organization_id to req.decodedToken.tenant_code correctly aligns with the updated service method signature. Based on the retrieved learnings, tenant_code from req.decodedToken is guaranteed to be present after token validation.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch admin-create-api

🪧 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.
  • 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.

Support

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

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 Switch user acceptance logic from organization_id to tenant_code identifier Aug 4, 2025
@nevil-mathew nevil-mathew merged commit e13d2e1 into develop Aug 4, 2025
1 of 2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 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