Add advanced user search with filters and pagination to database layer#788
Add advanced user search with filters and pagination to database layer#788
Conversation
WalkthroughA new advanced user search function was added to the database layer, supporting multiple filters, pagination, and organization-role relationships. The account service was refactored to use this new search, consolidating listing and searching with enhanced filtering. The account validator was updated to enforce validation on the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Validator
participant AccountService
participant Database
Client->>Validator: Send search request with params
Validator->>Client: Validate params (tenant_code, etc.)
Validator->>AccountService: Forward validated params
AccountService->>Database: Call searchUsersWithOrganization(options)
Database-->>AccountService: Return users and count
AccountService->>AccountService: Decrypt emails, resolve image URLs
AccountService-->>Client: Respond with user data and count
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)src/services/**⚙️ CodeRabbit Configuration File
Files:
🧠 Learnings (1)📓 Common learnings🔇 Additional comments (3)
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/validators/v1/account.js (1)
243-247: Improve error message clarityThe error message "tenant_code type value" is unclear. Consider making it more descriptive.
Apply this diff to improve the error message:
req.checkQuery('tenant_code') .notEmpty() .withMessage('tenant_code can not be null') .isString() - .withMessage('tenant_code type value') + .withMessage('tenant_code must be a string')
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/database/queries/users.js(1 hunks)src/services/account.js(3 hunks)src/validators/v1/account.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/validators/**
⚙️ CodeRabbit Configuration File
Validate all incoming data thoroughly. Check for missing or incomplete validation rules.
Files:
src/validators/v1/account.js
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/users.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 (6)
📓 Common learnings
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#783
File: src/database/queries/fileUpload.js:40-59
Timestamp: 2025-08-06T07:27:08.445Z
Learning: In the ELEVATE-Project/user repository, pagination is handled by src/middlewares/pagination.js which validates page and limit parameters and sets req.pageNo and req.pageSize. Service methods like getBulkInvitesFilesList use these pre-validated values when calling database query functions like listUploads. Additional parameter validation in database query functions is redundant since the middleware handles validation upstream.
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#783
File: src/database/queries/fileUpload.js:40-59
Timestamp: 2025-08-06T07:27:08.445Z
Learning: In the ELEVATE-Project/user repository, pagination parameters are validated by src/middlewares/pagination.js middleware which sets req.pageNo and req.pageSize. Service methods like getBulkInvitesFilesList use these pre-validated values when calling database query functions. Database query functions like listUploads receive already-validated pagination parameters, so additional validation in the query layer is redundant.
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.
📚 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/validators/v1/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/validators/v1/account.js
📚 Learning: in the elevate-project/user repository, pagination is handled by src/middlewares/pagination.js which...
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#783
File: src/database/queries/fileUpload.js:40-59
Timestamp: 2025-08-06T07:27:08.445Z
Learning: In the ELEVATE-Project/user repository, pagination is handled by src/middlewares/pagination.js which validates page and limit parameters and sets req.pageNo and req.pageSize. Service methods like getBulkInvitesFilesList use these pre-validated values when calling database query functions like listUploads. Additional parameter validation in database query functions is redundant since the middleware handles validation upstream.
Applied to files:
src/validators/v1/account.jssrc/database/queries/users.js
📚 Learning: in the elevate-project/user repository, pagination parameters are validated by src/middlewares/pagin...
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#783
File: src/database/queries/fileUpload.js:40-59
Timestamp: 2025-08-06T07:27:08.445Z
Learning: In the ELEVATE-Project/user repository, pagination parameters are validated by src/middlewares/pagination.js middleware which sets req.pageNo and req.pageSize. Service methods like getBulkInvitesFilesList use these pre-validated values when calling database query functions. Database query functions like listUploads receive already-validated pagination parameters, so additional validation in the query layer is redundant.
Applied to files:
src/validators/v1/account.js
📚 Learning: in the elevate-project/user repository, pagination parameters (page and limit) are validated in src/...
Learnt from: nevil-mathew
PR: ELEVATE-Project/user#783
File: src/database/queries/fileUpload.js:40-59
Timestamp: 2025-08-06T07:28:13.285Z
Learning: In the ELEVATE-Project/user repository, pagination parameters (page and limit) are validated in src/middlewares/pagination.js middleware which is applied globally to all routes. The middleware sets req.pageNo and req.pageSize with proper validation, so database query functions like listUploads don't need additional parameter validation.
Applied to files:
src/validators/v1/account.js
🧬 Code Graph Analysis (1)
src/database/queries/users.js (7)
src/database/queries/tenants.js (2)
offset(42-42)limit(41-41)src/services/admin.js (3)
userIds(619-619)userIds(656-656)users(610-617)src/services/org-admin.js (2)
userIds(418-418)roleIds(552-552)src/services/account.js (8)
userIds(1546-1546)emailIds(1868-1868)emailIds(2043-2043)users(1569-1569)users(1609-1616)users(1880-1890)users(2054-2054)roleIds(1867-1867)src/database/queries/orgRoleRequest.js (1)
userIds(145-145)src/services/userInvite.js (1)
userIds(214-214)src/controllers/v1/public.js (1)
tenantCode(7-7)
🔇 Additional comments (1)
src/services/account.js (1)
1851-1851: No remaininglistreferences; renaming tosearchis safeRan the provided ripgrep and fd searches across all JS files and controller definitions—no occurrences of
AccountHelper.list,account.list, or similar.listcalls remain.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor