Skip to content

Conversation

@adithyadinesh0412
Copy link
Collaborator

@adithyadinesh0412 adithyadinesh0412 commented Sep 1, 2025

Summary by CodeRabbit

  • New Features
    • Listing organizations now supports optional filtering by one or more organization codes.
    • Accepts codes provided as an array or a comma-separated string (case-insensitive, trimmed).
    • Recognizes tenant parameter in multiple common formats for compatibility.
    • Existing tenant and active-status filters remain enforced; requests without codes behave unchanged.

@coderabbitai
Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

OrganizationsHelper.list now reads tenant code from query (supports tenant_code and tenantCode), builds a filters object always containing tenant_code and status: ACTIVE, optionally adds a code filter using Op.in when organization_codes/organizationCodes are provided (CSV or array), and calls organizationQueries.findAll(filters, options).

Changes

Cohort / File(s) Summary of Changes
Organizations list filtering
src/services/organization.js
Read tenant code from query (tenant_code or tenantCode); construct filters object with tenant_code and status: ACTIVE; accept organization_codes or organizationCodes from query (CSV or array), normalize lowercase/trim and set filters.code = Op.in(codes); call organizationQueries.findAll(filters, options) instead of an inlined filter.

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[]
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • nevil-mathew

Poem

I hop through params, sniff tenant codes,
CSV or arrays in tidy rows.
I trim and lower, then gather the crew,
Op.in lines them up—all set, who knew?
A rabbit's nod: filters stitched true. 🥕


📜 Recent 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.

📥 Commits

Reviewing files that changed from the base of the PR and between d006988 and 75d98b7.

📒 Files selected for processing (1)
  • src/services/organization.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/organization.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/services/organization.js (2)

259-263: Prefer const for filters

The 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.

📥 Commits

Reviewing files that changed from the base of the PR and between d734d91 and d006988.

📒 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 the filters object—including any Op.in clauses—directly in the where option to Sequelize.

@nevil-mathew nevil-mathew merged commit 7b7e749 into ELEVATE-Project:develop Sep 1, 2025
1 check passed
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