Refactor file upload queries and tenant scoping across codebase#783
Refactor file upload queries and tenant scoping across codebase#783
Conversation
WalkthroughThis update modifies the handling of file upload queries and tenant scoping across the codebase. Changes include refactoring the Changes
Sequence Diagram(s)sequenceDiagram
participant OrgAdminHelper
participant fileUploadQueries
participant FileUploadModel
OrgAdminHelper->>fileUploadQueries: listUploads({ page, limit, filter })
fileUploadQueries->>FileUploadModel: findAll({ where: filter, ... })
FileUploadModel-->>fileUploadQueries: Raw rows
fileUploadQueries-->>OrgAdminHelper: Raw upload rows
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ 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: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/database/models/fileUpload.js(0 hunks)src/database/queries/fileUpload.js(3 hunks)src/services/account.js(1 hunks)src/services/org-admin.js(1 hunks)src/validators/v1/org-admin.js(1 hunks)
💤 Files with no reviewable changes (1)
- src/database/models/fileUpload.js
🧰 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/org-admin.js
src/services/**
⚙️ CodeRabbit Configuration File
This is core business logic. Please check for correctness, efficiency, and potential edge cases.
Files:
src/services/account.jssrc/services/org-admin.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/fileUpload.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.
📚 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/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/services/account.js
🔇 Additional comments (5)
src/validators/v1/org-admin.js (1)
19-19: LGTM - Critical validation fix.The
.isIn()validator now correctly receives theupload_typearray as an argument, which was missing before. This ensures proper validation of theupload_typefield against the allowed values.src/services/account.js (1)
910-919: LGTM! Proper tenant isolation for session lookups.The addition of
tenant_codefiltering to the user session lookup ensures proper tenant-specific data isolation. This aligns well with the broader PR objective of enhancing tenant-aware querying across the codebase.src/database/queries/fileUpload.js (2)
2-2: LGTM! Import path modernization.Using absolute alias paths improves maintainability and consistency across the codebase.
10-10: LGTM! Improved error propagation.Changing from
return errortothrow errorprovides better error handling by allowing errors to bubble up properly to calling code.Also applies to: 22-22, 36-36, 57-57
src/services/org-admin.js (1)
194-202: LGTM! Proper implementation of updated listUploads interface with tenant isolation.The refactored call correctly implements the new object-based parameter structure and properly includes
tenant_codefor tenant-aware filtering. The conditional status inclusion using the spread operator is clean and the overall change aligns well with the tenant isolation improvements across the codebase.
Summary by CodeRabbit
upload_typefield to ensure only allowed values are accepted.