Skip to content

Feature/program sync#327

Merged
VISHNUDAS-tunerlabs merged 27 commits intomasterfrom
feature/program_sync
Aug 12, 2025
Merged

Feature/program sync#327
VISHNUDAS-tunerlabs merged 27 commits intomasterfrom
feature/program_sync

Conversation

@borkarsaish65
Copy link
Copy Markdown
Collaborator

@borkarsaish65 borkarsaish65 commented Jul 24, 2025

Summary by CodeRabbit

  • New Features

    • Added new routes to support fetching and merging user solutions from both project and survey services.
    • Introduced enhanced program fetching capabilities for user solutions, supporting both individual and bulk queries.
    • Implemented response merging for program data, improving data aggregation across services.
    • Enabled dynamic merging of program responses via a new handler for streamlined data processing.
  • Bug Fixes

    • None.
  • Chores

    • Updated route configurations to include new functionalities and improve integration between services.

Copy link
Copy Markdown
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs left a comment

Choose a reason for hiding this comment

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

Reviewed on Jul 28 1: 8

Copy link
Copy Markdown
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs left a comment

Choose a reason for hiding this comment

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

Approved on Jul 28

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 30, 2025

Walkthrough

This update refines route configurations to support merged program solutions from both "project" and "survey" services. It adds new controller methods to fetch and merge program data, introduces a generic merge handler to invoke these methods dynamically, and updates exports accordingly. Interface routes are extended with new POST entries requiring custom handling.

Changes

Cohort / File(s) Change Summary
Project Route Config Updates
elevate-project/constants/routes.js
Updated routes for /interface/v1/users/solutions and /interface/v1/users/solutions/:id to include functionName: "getMergedProgramSolutions" and replaced single path with multiple paths targeting both project and survey services. Added a duplicate route entry for /interface/v1/users/solutions/:id with the new config.
Project Controller Enhancements
elevate-project/controllers/project.js
Added asynchronous method getMergedProgramSolutions that concurrently fetches program solutions from project and survey services, merges results by programId, and sorts data by order. Exported this method in projectController.
Custom Merge Handler
elevate-project/customMergeFunctionHandler/index.js
Created mergeHandler function that dynamically calls a merge function by name from projectController, throwing an error if the function does not exist. Exported as default.
Project Index Export
elevate-project/index.js
Imported and exported customMergeFunctionHandler alongside existing exports.
Survey Route Config Updates
elevate-survey/constants/routes.js
Added functionName: "fetchPrograms" to targetRoute objects for /interface/v1/users/solutions and /interface/v1/users/solutions/:id.
Survey Controller Enhancement
elevate-survey/controllers/survey.js
Added asynchronous fetchPrograms method that forwards POST requests to the appropriate survey service route, handling errors and exporting the method.
Interface Route Additions
interface-routes/elevate-dev-routes.json
Added two new POST routes for /interface/v1/users/solutions and /interface/v1/users/solutions/:id with priority, sequence, custom handling, and targeting the project service package.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Orchestrator
    participant ProjectService
    participant SurveyService
    participant MergeHandler

    Client->>Orchestrator: POST /interface/v1/users/solutions
    Orchestrator->>ProjectService: getMergedProgramSolutions
    ProjectService->>ProjectService: build URLs for project & survey
    ProjectService->>ProjectService: send concurrent POST requests
    ProjectService-->>Orchestrator: program data from both services
    Orchestrator->>MergeHandler: mergeHandler with functionName
    MergeHandler-->>Orchestrator: merged program data
    Orchestrator-->>Client: Respond with merged data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

🐇 In tunnels deep where data flows,
New routes and merges swiftly grow.
Project and Survey hand in hand,
Fetching programs across the land.
With tokens passed and calls aligned,
The rabbit’s code now well-designed.
Hop, merge, and run — a job well done! 🥕✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/program_sync

🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
  • 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 src/utils.ts and explain its main purpose.
    • @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 comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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
Copy Markdown

@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: 4

🧹 Nitpick comments (4)
elevate-project/customMergeFunctionHandler/index.js (2)

3-3: Remove console.log from production code.

This debug statement should be removed before deploying to production to avoid cluttering logs.

-    console.log({result, functionName, packages})

2-2: Consider using the packages parameter or removing it.

The packages parameter is received but never used in the function. If it's intended for future use, consider adding a comment explaining its purpose, or remove it if it's not needed.

elevate-project/controllers/project.js (1)

281-291: Consider consolidating duplicated fetchPrograms logic.

The fetchPrograms function is nearly identical to the one in elevate-survey/controllers/survey.js. Consider extracting this common logic into a shared utility function to reduce code duplication.

This could be moved to a shared utility module that both controllers can import and use.

interface-routes/elevate-dev-routes.json (1)

12399-12403: Hard-coding basePackageName duplicates information already present in targetPackages

mergeConfiguration.basePackageName repeats the value carried by the first targetPackages element.
When another developer later changes the package array (e.g. switches order or renames), this duplication becomes a maintenance hazard and a silent source of bugs if only one copy is updated.

Consider relying solely on mergeConfiguration.packageName (the fully-qualified NPM package) or deriving the basePackageName dynamically inside the merge handler.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1652430 and 82c93c2.

📒 Files selected for processing (7)
  • elevate-project/constants/routes.js (2 hunks)
  • elevate-project/controllers/project.js (1 hunks)
  • elevate-project/customMergeFunctionHandler/index.js (1 hunks)
  • elevate-project/index.js (2 hunks)
  • elevate-survey/constants/routes.js (2 hunks)
  • elevate-survey/controllers/survey.js (1 hunks)
  • interface-routes/elevate-dev-routes.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
elevate-project/customMergeFunctionHandler/index.js (1)
elevate-project/controllers/project.js (2)
  • projectController (320-328)
  • require (11-11)
elevate-project/controllers/project.js (6)
elevate-survey/controllers/survey.js (7)
  • fetchPrograms (158-168)
  • selectedConfig (30-30)
  • selectedConfig (159-159)
  • routeConfigs (8-8)
  • targetedRoutePath (160-160)
  • params (161-161)
  • requesters (9-9)
elevate-self-creation-portal/controllers/selfCreationPortal.js (3)
  • selectedConfig (8-8)
  • routeConfigs (1-1)
  • requesters (2-2)
elevate-project/utils/requester.js (2)
  • params (23-23)
  • requesters (136-142)
elevate-project/customMergeFunctionHandler/index.js (1)
  • projectController (1-1)
elevate-project/controllers/customHandler.js (1)
  • projectController (2-2)
elevate-project/controllers/orchestrationController.js (1)
  • projectController (2-2)
🔇 Additional comments (7)
elevate-project/index.js (1)

5-5: LGTM! Clean module export pattern.

The addition of the customMergeFunctionHandler import and export follows a standard pattern and integrates well with the existing module structure.

Also applies to: 38-38

elevate-survey/constants/routes.js (1)

2955-2956: LGTM! Consistent route configuration.

The addition of functionName: "fetchPrograms" to both solution routes is consistent and properly aligns with the fetchPrograms function added to the survey controller. The orchestrated routes will now correctly reference the appropriate controller function.

Also applies to: 2967-2968

elevate-project/constants/routes.js (1)

3059-3061: LGTM! Function name configuration is properly added.

The addition of functionName: "fetchPrograms" to both solution routes is consistent and aligns with the orchestration framework. This enables dynamic routing to the appropriate controller function.

Also applies to: 3071-3073

elevate-project/controllers/project.js (2)

293-318: LGTM! Well-implemented merge function with proper error handling.

The mergeProgramResponse function correctly merges program responses by programId, accumulates data arrays, sums counts, and includes appropriate error handling. The logic for cloning objects to avoid mutations is also well implemented.


325-327: LGTM! Controller exports properly updated.

The new functions are correctly added to the exported projectController object, maintaining consistency with the existing export pattern.

interface-routes/elevate-dev-routes.json (2)

12396-12404: Route-level requiresCustomHandling likely redundant

The route itself (Lines 12396-12399) already sets "inSequence": true and a mergeConfiguration.
Historically the orchestrator only inspects the requiresCustomHandling flag inside each targetPackages entry; a route-level flag isn’t defined in the published schema. Retaining it may be harmless, but if strict validation is enabled this could reject the whole route object.

Request double-check against interface-routes/schema.json (or the loader implementation) before merging.


12448-12459: Non-unique mergeKey values may collide across parallel orchestrations

Both new routes use "mergeKey": "first" / "second" inside their respective targetPackages.
If multiple interface calls are executed concurrently (e.g. /solutions and /solutions/:id) the simplistic keys can collide in the shared aggregator context, leading to data coming from the wrong service.

Safer pattern: encode the service or route in the key, for example "project_first" / "survey_second" or simply omit the field and let the orchestrator generate a UUID.

@borkarsaish65
Copy link
Copy Markdown
Collaborator Author

@coderabbitai I have addressed all the comments by you, please check and approve from your side

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 1, 2025

🧩 Analysis chain

I'll review the changes to ensure everything is properly implemented before approving the PR.


🏁 Script executed:

#!/bin/bash
# First, let's examine the main controller implementations
echo "=== Examining project controller ==="
cat elevate-project/controllers/project.js

echo -e "\n=== Examining survey controller ==="
cat elevate-survey/controllers/survey.js

echo -e "\n=== Examining custom merge handler ==="
cat elevate-project/customMergeFunctionHandler/index.js

echo -e "\n=== Examining route configurations ==="
echo "Project routes:"
cat elevate-project/constants/routes.js

echo -e "\nSurvey routes:"
cat elevate-survey/constants/routes.js

echo -e "\n=== Examining interface routes ==="
cat interface-routes/elevate-dev-routes.json

Length of output: 324137


@borkarsaish65 All comments have been addressed and the implementation looks good. Approving the PR.

✅ Actions performed

Comments resolved.

@borkarsaish65
Copy link
Copy Markdown
Collaborator Author

@coderabbitai added some minor changes , please review and approve if no change is required

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 1, 2025

🧩 Analysis chain

I'll review the recent changes you've made to ensure everything is still properly implemented.


🏁 Script executed:

#!/bin/bash
# Let's examine the current state of the main files to identify any recent changes
echo "=== Current project controller implementation ==="
cat elevate-project/controllers/project.js

echo -e "\n=== Current survey controller implementation ==="
cat elevate-survey/controllers/survey.js

echo -e "\n=== Current custom merge handler ==="
cat elevate-project/customMergeFunctionHandler/index.js

echo -e "\n=== Current project routes ==="
cat elevate-project/constants/routes.js

echo -e "\n=== Current survey routes ==="
cat elevate-survey/constants/routes.js

echo -e "\n=== Current interface routes configuration ==="
head -50 interface-routes/elevate-dev-routes.json

Length of output: 194511


Let me check the complete interface routes configuration to see the new routes that were added:


🏁 Script executed:

#!/bin/bash
# Check for the specific interface routes that were added
echo "=== Checking for interface routes with solutions ==="
grep -A 20 -B 5 "users/solutions" interface-routes/elevate-dev-routes.json

echo -e "\n=== Checking the main index file export ==="
cat elevate-project/index.js

echo -e "\n=== Verifying no syntax errors in key files ==="
node -c elevate-project/controllers/project.js && echo "✓ Project controller syntax OK"
node -c elevate-survey/controllers/survey.js && echo "✓ Survey controller syntax OK" 
node -c elevate-project/customMergeFunctionHandler/index.js && echo "✓ Custom merge handler syntax OK"

Length of output: 4789


@borkarsaish65 I've reviewed the current state of the implementation and everything looks excellent! The recent changes you mentioned are all properly implemented:

Interface Routes: The new orchestrated routes for /interface/v1/users/solutions are correctly configured with merge functionality
Controllers: Both project and survey controllers have the fetchPrograms function properly implemented
Custom Merge Handler: The merge handler is correctly exported and implemented
Route Configurations: All route configurations have the proper functionName references
Syntax: All files pass syntax validation without errors

The implementation is solid and ready to go. No changes are required.

✅ Actions performed

Comments resolved.

Copy link
Copy Markdown

@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: 1

🔭 Outside diff range comments (1)
elevate-project/constants/routes.js (1)

3075-3094: Fix the service property placement in the paths array.

The service: 'survey' property at line 3087 is incorrectly nested within the path object. It should be at the same level as path and type properties.

Apply this diff to fix the structure:

 				paths: [
 					{
 						path: '/project/v1/users/solutions/:id',
 						type: 'POST',
 					},
-					{   service: 'survey',
+					{
+						service: 'survey',
 						path: '/survey/v1/users/solutions/:id',
 						type: 'POST',
 					},
 				],
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b294339 and cdbe593.

📒 Files selected for processing (2)
  • elevate-project/constants/routes.js (1 hunks)
  • elevate-project/controllers/project.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • elevate-project/controllers/project.js
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: interface-routes/elevate-dev-routes.json:0-0
Timestamp: 2025-08-05T09:46:57.365Z
Learning: In the ELEVATE project, "deletedResourceDetails" endpoints use POST method instead of GET, even though they appear to be read-only operations. This is by design based on project-specific requirements.
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:50.071Z
Learning: In the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for all route configurations. Out of 293 total routes, 33 routes (about 11%) exist without this property, making it optional rather than required.
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:50.071Z
Learning: In the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for all route configurations. Many routes exist without this property, making it optional rather than required.
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:07.320Z
Learning: In route configuration files like elevate-project/constants/routes.js, the `orchestrated` property is optional and not required for all endpoints. Some routes have `orchestrated: false` while others omit this property entirely.
📚 Learning: in the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for a...
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:50.071Z
Learning: In the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for all route configurations. Many routes exist without this property, making it optional rather than required.

Applied to files:

  • elevate-project/constants/routes.js
📚 Learning: in the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for a...
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:50.071Z
Learning: In the elevate-project/constants/routes.js file, the `orchestrated` property is not compulsory for all route configurations. Out of 293 total routes, 33 routes (about 11%) exist without this property, making it optional rather than required.

Applied to files:

  • elevate-project/constants/routes.js
📚 Learning: in route configuration files like elevate-project/constants/routes.js, the `orchestrated` property i...
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:0-0
Timestamp: 2025-08-05T09:46:07.320Z
Learning: In route configuration files like elevate-project/constants/routes.js, the `orchestrated` property is optional and not required for all endpoints. Some routes have `orchestrated: false` while others omit this property entirely.

Applied to files:

  • elevate-project/constants/routes.js
📚 Learning: in the elevate project, "deletedresourcedetails" endpoints use post method instead of get, even thou...
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: interface-routes/elevate-dev-routes.json:0-0
Timestamp: 2025-08-05T09:46:57.365Z
Learning: In the ELEVATE project, "deletedResourceDetails" endpoints use POST method instead of GET, even though they appear to be read-only operations. This is by design based on project-specific requirements.

Applied to files:

  • elevate-project/constants/routes.js
📚 Learning: in route configurations for the elevate project, the `orchestrated` property is not mandatory for al...
Learnt from: MallanagoudaB
PR: ELEVATE-Project/utils#329
File: elevate-project/constants/routes.js:3128-3137
Timestamp: 2025-08-05T09:46:00.231Z
Learning: In route configurations for the ELEVATE project, the `orchestrated` property is not mandatory for all endpoints. Some routes explicitly set `orchestrated: false`, some omit the property entirely, and some set it to `true` (typically when `inSequence: true` is also set for interface routes). The presence or absence of the `orchestrated` property depends on the specific requirements of each route.

Applied to files:

  • elevate-project/constants/routes.js

Comment on lines +3095 to +3115
{
sourceRoute: '/interface/v1/users/solutions/:id',
type: 'POST',
inSequence: true,
orchestrated: true,
targetRoute: {
type: 'POST',
functionName: 'getMergedProgramSolutions',
paths: [
{
path: '/project/v1/users/solutions/:id',
type: 'POST',
},
{ service: 'survey',
path: '/survey/v1/users/solutions/:id',
type: 'POST',
},
],
},
service: 'project',
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the service property placement and verify route duplication.

The same structural issue exists here with the service: 'survey' property placement at line 3108. Additionally, both interface routes have identical targetRoute configurations - verify this is intentional for the merge functionality.

Apply this diff to fix the structure:

 			targetRoute: {
 				type: 'POST',
 				functionName: 'getMergedProgramSolutions',
 				paths: [
 					{
 						path: '/project/v1/users/solutions/:id',
 						type: 'POST',
 					},
-					{   service: 'survey',
+					{
+						service: 'survey',
 						path: '/survey/v1/users/solutions/:id',
 						type: 'POST',
 					},
 				],
 			},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
sourceRoute: '/interface/v1/users/solutions/:id',
type: 'POST',
inSequence: true,
orchestrated: true,
targetRoute: {
type: 'POST',
functionName: 'getMergedProgramSolutions',
paths: [
{
path: '/project/v1/users/solutions/:id',
type: 'POST',
},
{ service: 'survey',
path: '/survey/v1/users/solutions/:id',
type: 'POST',
},
],
},
service: 'project',
},
targetRoute: {
type: 'POST',
functionName: 'getMergedProgramSolutions',
paths: [
{
path: '/project/v1/users/solutions/:id',
type: 'POST',
},
{
service: 'survey',
path: '/survey/v1/users/solutions/:id',
type: 'POST',
},
],
},
🤖 Prompt for AI Agents
In elevate-project/constants/routes.js around lines 3095 to 3115, the service
property for the survey route is incorrectly placed inside the paths array
object instead of alongside the other route properties. Move the service:
'survey' property out of the path object and place it at the same level as path
and type within the paths array. Also, review the two interface routes with
identical targetRoute configurations to confirm if this duplication is
intentional for the merge functionality; if not, adjust accordingly.

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs merged commit cdbe593 into master Aug 12, 2025
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 13, 2025
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