Org list fix for SCP#809
Conversation
WalkthroughOrganizationsHelper.list now reads tenant code from query (supports Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Helper as OrganizationsHelper.list
participant DB as organizationQueries
Client->>Helper: list(params(query), options)
activate Helper
Helper->>Helper: Read tenantCode ← query.tenant_code || query.tenantCode
Helper->>Helper: filters = { tenant_code: tenantCode, status: ACTIVE }
alt organization_codes provided
Helper->>Helper: Read codes ← query.organization_codes || query.organizationCodes
Helper->>Helper: Normalize (split CSV or use array) → trim & toLowerCase codes[]
Helper->>Helper: filters.code = Op.in(codes)
else no codes
Note over Helper: filters remain tenant_code + status
end
Helper->>DB: findAll(filters, options)
DB-->>Helper: organizations[]
deactivate Helper
Helper-->>Client: organizations[]
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 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/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/services/organization.js (2)
259-263: Prefer const for filtersThe reference isn’t reassigned; const communicates intent and avoids accidental rebinds.
- let filters = { + const filters = { tenant_code: params?.query?.tenantCode, status: common.ACTIVE_STATUS, }
264-271: Harden organizationCodes parsing (trim, dedupe, JSON-string support, and skip empty IN)Prevents false negatives from whitespace/duplicates, supports JSON array strings (parity with organizationIds handling), and avoids IN ([]).
- // fetch list by org codes - if (params.body && params.body.organizationCodes) { - const orgCodes = Array.isArray(params.body.organizationCodes) - ? params.body.organizationCodes - : params.body.organizationCodes.split(',').map((code) => code.trim()) - filters.code = { - [Op.in]: orgCodes, - } - } + // fetch list by org codes + if (params.body?.organizationCodes != null) { + const raw = params.body.organizationCodes + let orgCodes = [] + if (Array.isArray(raw)) { + orgCodes = raw + } else if (typeof raw === 'string') { + const s = raw.trim() + if (s.startsWith('[') && s.endsWith(']')) { + try { + orgCodes = JSON.parse(s) + } catch { + orgCodes = s.split(',') + } + } else { + orgCodes = s.split(',') + } + } + orgCodes = [...new Set(orgCodes.map((c) => String(c).trim()).filter(Boolean))] + if (orgCodes.length > 0) { + filters.code = { [Op.in]: orgCodes } + } + }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/services/organization.js(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/services/**
⚙️ CodeRabbit configuration file
This is core business logic. Please check for correctness, efficiency, and potential edge cases.
Files:
src/services/organization.js
🔇 Additional comments (1)
src/services/organization.js (1)
273-273: Verify that organizationQueries.findAll preserves Sequelize operators (Op.in)
Double-check the implementation in the query layer (e.g. src/database/queries/organizationQueries.js) to ensure it forwards thefiltersobject—including anyOp.inclauses—directly in thewhereoption to Sequelize.
Summary by CodeRabbit