feat(tenant): add readInternal method for internal service calls#819
feat(tenant): add readInternal method for internal service calls#819
Conversation
WalkthroughInternal access URL for tenant read was updated to point to a new internal route, and a new controller method readInternal(req) was added to return tenant details using tenantService.read with admin context. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant S as Internal Service
participant R as Router
participant C as TenantController
participant TS as tenantService
participant DB as Data Store
S->>R: GET /user/v1/tenant/readInternal/:id
R->>C: readInternal(req)
alt Missing tenant code
C-->>S: 400 TENANT_CODE_REQUIRED
else Valid tenant code
C->>TS: read(tenantCode, true)
TS->>DB: Query tenant (admin context)
DB-->>TS: Tenant data
TS-->>C: Result
C-->>S: 200 Tenant data
end
note over C,TS: New internal flow using isAdmin=true
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests✅ Unit Test PR creation complete.
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/controllers/v1/tenant.js (1)
169-178: Minor: tighten param extraction and document HTTP method.Use optional chaining + trim to avoid accidental whitespace issues and align with file style. Also annotate the method as GET in JSDoc.
Apply:
- /** - * Read tenant details for internal service calls - * @method + /** + * Read tenant details for internal service calls + * @method GET * @name readInternal * @param {Object} req - request data * @param {String} req.params.id - tenant code to fetch details for * @returns {JSON} - tenant details without any filtering for internal service use */ @@ - async readInternal(req) { + async readInternal(req) { try { - const tenantCode = req.params.id - if (!tenantCode) { + const tenantCode = req?.params?.id?.trim() + if (!tenantCode) { return responses.failureResponse({ statusCode: httpStatusCode.bad_request, message: 'TENANT_CODE_REQUIRED', result: {}, })src/constants/common.js (1)
33-35: Ensure internalAccessUrls matching accounts for trailing slashes.authenticator uses req.path.includes(path) (src/middlewares/authenticator.js:64–66); because the constant entry ends with '/', requests without the trailing slash (e.g. /user/v1/tenant/readInternal) will not match. Remove the trailing slash from the constant, normalize/truncate trailing slashes on both req.path and the list, or switch to prefix matching (req.path.startsWith(path)).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/constants/common.js(1 hunks)src/controllers/v1/tenant.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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/tenant.js
🧬 Code graph analysis (1)
src/controllers/v1/tenant.js (2)
src/services/tenant.js (2)
responses(31-31)httpStatusCode(9-9)src/helpers/responses.js (1)
error(28-28)
|
Note Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
✅ UTG Post-Process Complete No new issues were detected in the generated code and all check runs have completed. The unit test generation process has completed successfully. |
|
Creating a PR to put the unit tests in... The changes have been created in this pull request: View PR |
Summary by CodeRabbit
New Features
Chores