Skip to content

Related org code#813

Merged
nevil-mathew merged 12 commits intodevelopfrom
relatedOrg_code
Sep 8, 2025
Merged

Related org code#813
nevil-mathew merged 12 commits intodevelopfrom
relatedOrg_code

Conversation

@praveenKDass
Copy link
Collaborator

@praveenKDass praveenKDass commented Sep 4, 2025

Summary by CodeRabbit

  • New Features
    • Organization detail responses now include a concise “related organizations” summary when available, listing linked organizations (ID and code) for quicker cross-referencing.
    • Consumers (views, integrations) can surface these related organizations to streamline navigation between linked entities.
    • If no related organizations exist, responses remain unchanged to preserve backward compatibility and existing workflows.

@coderabbitai
Copy link

coderabbitai bot commented Sep 4, 2025

Walkthrough

Augments OrganizationsHelper.read to, when organisationDetails.related_orgs is present and non-empty, fetch related organizations by ID and attach organisationDetails.related_org_details as an array of { id, code }. No API signatures changed; behavior unchanged when related_orgs is absent.

Changes

Cohort / File(s) Summary
Organization service: enrich read response
src/services/organization.js
After reading organisationDetails, if related_orgs contains IDs, query those orgs and attach organisationDetails.related_org_details as an array of { id, code }. Payload augmented conditionally; no status/message or signature changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant OrganizationsHelper
  participant OrgRepo as Organization Repository

  Client->>OrganizationsHelper: read(id)
  OrganizationsHelper->>OrgRepo: getOrganizationById(id)
  OrgRepo-->>OrganizationsHelper: organisationDetails

  alt related_orgs present and non-empty
    note right of OrganizationsHelper: New: fetch related orgs by IDs
    OrganizationsHelper->>OrgRepo: getOrganizationsByIds(related_orgs[])
    OrgRepo-->>OrganizationsHelper: [{ id, code }, ...]
    OrganizationsHelper->>OrganizationsHelper: attach organisationDetails.related_org_details
  else no related_orgs
    note right of OrganizationsHelper: Return original organisationDetails
  end

  OrganizationsHelper-->>Client: organisationDetails (+ optional related_org_details)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • nevil-mathew

Poem

I hop through rows of org IDs bright,
Nose twitching, I fetch kin by night.
I tuck in codes with a careful paw,
Related homes found — I take a bow.
A tiny rabbit's delight, voilà! 🐇✨

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b463c9 and 4865614.

📒 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
  • Commit unit tests in branch relatedOrg_code

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/services/organization.js (1)

409-411: Guard against null/undefined tenantCode before calling .trim()

tenantCode defaults to null; calling tenantCode.trim() can throw. Add a null-safe check.

-                if (tenantCode.trim()) filter.tenant_code = tenantCode
+                if (tenantCode && String(tenantCode).trim()) filter.tenant_code = tenantCode
🧹 Nitpick comments (1)
src/package.json (1)

19-19: Make operator intent explicit in db:init

Parenthesize to avoid ambiguity and improve readability. Behavior remains the same.

-        "db:init": "sequelize-cli db:create || echo 'Database already exists or some issue while creating db, Please check' && sequelize-cli db:migrate ",
+        "db:init": "(sequelize-cli db:create || echo 'Database already exists or some issue while creating db, Please check') && sequelize-cli db:migrate",
📜 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 095175f and 0df6689.

⛔ Files ignored due to path filters (1)
  • README.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • src/package.json (1 hunks)
  • 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

@nevil-mathew
Copy link
Collaborator

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

✅ Actions performed

Full review triggered.

Comment on lines +429 to +437
//Get related orgs with code
if (organisationDetails.related_orgs && organisationDetails.related_orgs.length > 0) {
let orgFilters = { id: { [Op.in]: organisationDetails.related_orgs } }
const relatedOrgsIdAndCode = await organizationQueries.findAll(orgFilters)
organisationDetails.related_org_details = relatedOrgsIdAndCode.map((eachOrg) => ({
id: eachOrg.id,
code: eachOrg.code,
}))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update this block to query only the required fields using attributes: ['id', 'code'] and drop the .map logic.
Also, initialize organisationDetails.related_org_details = [] before the condition so the key is always present in the response, even when related_orgs is empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

organisationDetails.related_org_details = []

if (organisationDetails.related_orgs && organisationDetails.related_orgs.length > 0) {
  const options = {
    attributes: ['id', 'code'],
  }

  organisationDetails.related_org_details = await organizationQueries.findAll(
    { id: { [Op.in]: organisationDetails.related_orgs } },
    options
  )
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated the code as per the comment @nevil-mathew

@nevil-mathew nevil-mathew merged commit be09029 into develop Sep 8, 2025
1 of 2 checks 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.

4 participants