Skip to content

moving-changes-to-main#754

Open
MallanagoudaB wants to merge 1 commit into
ELEVATE-Project:mainfrom
MallanagoudaBiradar:MovingToMain
Open

moving-changes-to-main#754
MallanagoudaB wants to merge 1 commit into
ELEVATE-Project:mainfrom
MallanagoudaBiradar:MovingToMain

Conversation

@MallanagoudaB
Copy link
Copy Markdown
Collaborator

@MallanagoudaB MallanagoudaB commented May 8, 2026

Description

These recommendations are intended to promote code quality and team communication during software development. They cover a variety of topics, including ensuring that pull requests are submitted to the correct branch, documenting new methods, preserving consistency across many services, and avoiding typical blunders like accessing APIs or DB queries within loops. Sensitive data should not be uploaded, and changes to environment variables or database models should be executed consistently. Teams may work more effectively and develop higher-quality software by adhering to these standards.

Type of change

Please choose appropriate options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Enhancement (additive changes to improve performance)
  • This change requires a documentation update

Checklist

  • It's critical to avoid making needless file modifications in contributions, such as adding new lines, console logs, or additional spaces, to guarantee cleaner and more efficient code. Furthermore, eliminating unnecessary imports from a file might enhance code readability and efficiency.
  • Ensure that the pull request is assigned to the right base branch and that the development branch name contains the JIRA Task Id. Furthermore, each commit message should include the JIRA Task Id in the manner "ED-100: message".
  • Only update packages if it is mentioned and authorized in the design document, and make sure that you have the required permissions.
  • Avoid making API and database queries inside a loop as it can lead to performance issues and slow down the system.
  • When calling another function inside a given function, add comments explaining the purpose and meaning of the passed arguments and expected return values.
  • If adding a blank argument in a function, add a comment explaining the reason for the blank argument.
  • Before submitting a pull request, do a self-review of your code to ensure there are no conflicts with the base branch and all comments have been addressed.
  • Before merging a pull request, it's important to have other team members review it to catch any potential errors or issues
  • To maintain code integrity, it's important to remove all related changes when removing code during a code review.
  • If new constants, endpoints, or utility functions are introduced, it is important to check if they already exist in the service to avoid any duplication.
  • Whenever a new environment variable is added to a service, it's important to ensure that the necessary changes are made to related files such as ".env.sample" and "envVariables.js" to maintain consistency and avoid errors. Additionally, the new environment variable should be added to the devops repository to ensure that it is properly documented and accessible to the team.
  • When adding a new function to a service, it is important to document it with relevant information such as the name, parameters, and return value in a consistent format across all services. Additionally, if there are any changes to the API response, ensure that the documentation in the controllers is updated accordingly.
  • Write a clear and concise commit message that describes the changes made.
  • Maintain consistent function signature and code across all services when adding a function to multiple services. Implement changes to database models in all services that use the same model.
  • Use only let and const. Do not use var.
  • Make common functions for repetitive code blocks.
  • Avoid uploading sensitive information such as secret tokens or passwords in pull requests to ensure data security.
  • Maintain consistent indentation and spacing throughout the code.

Summary by CodeRabbit

  • New Features
    • Enhanced resource deletion to properly support private program deletions with improved tracking of deleted resources.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds an isAPrivateProgram parameter to the survey deletion service and propagates it through the admin helper's deletion cascade for programs and solutions, enabling the survey service to receive program context during resource cleanup.

Changes

Private Program Deletion Flag Propagation

Layer / File(s) Summary
Service Function Signature
generics/services/survey.js
deleteSolutionResource signature updated to accept isAPrivateProgram parameter with updated JSDoc.
Service Payload Extension
generics/services/survey.js
POST request body now includes isAPrivateProgram in the JSON payload sent to the survey service endpoint.
Admin Helper Method Signature
module/admin/helper.js
deleteAssociatedResources method signature and JSDoc updated to accept isAPrivateProgram parameter.
Admin Helper Deletion Cascade
module/admin/helper.js
Program and solution deletion paths now forward deletedBy and isAPrivateProgram to surveyService.deleteSolutionResource and deleteAssociatedResources calls; program deletion additionally accumulates deletedSolutionsCount from the service response.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • VISHNUDAS-tunerlabs

Poem

🐰 A flag hops through deletion's hall,
Private programs standing tall,
Survey service takes the cue,
Parameter flows clean and true,
Cascade whispers, "Context knew!" ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is simply a copy of the repository template with all checklist items unchecked and no actual details about the changes being made. Replace the template content with a meaningful description of the changes, including why the isAPrivateProgram parameter was added and how it impacts the deletion flow.
Title check ❓ Inconclusive The title "moving-changes-to-main" is vague and generic, failing to describe the actual changes made to the codebase (adding isAPrivateProgram parameter to survey-related functions). Use a more descriptive title that captures the main change, such as "Add isAPrivateProgram parameter to survey resource deletion" or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

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.

Caution

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

⚠️ Outside diff range comments (2)
module/admin/helper.js (2)

267-276: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

projecFilter hardcodes isAPrivateProgram: false — will orphan projects of private programs/solutions when they are deleted.

The isAPrivateProgram parameter is available in the deletedResourceDetails() function and is conditionally used when deleting solutions and programs themselves (lines 188–195), but the project deletion filters at lines 267–276 and 359–366 hardcode it to false. When a private program or solution is deleted, private projects linked to it will not be matched by the filter and will be left orphaned with dangling parent references.

The parameter should be passed through to the project deletion filter:

Fix for both locations
 let projecFilter = {
   solutionId: { $in: solutionIds },
-  isAPrivateProgram: false,
+  isAPrivateProgram: isAPrivateProgram,
   tenantId: tenantId,
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@module/admin/helper.js` around lines 267 - 276, The project deletion filter
currently hardcodes the isAPrivateProgram flag (projecFilter) which will skip
private projects and leave them orphaned; update the filter used before calling
projectQueries.delete so it uses the isAPrivateProgram parameter passed into
deletedResourceDetails() (or the surrounding function) instead of always false;
locate the projecFilter construction(s) and replace the hardcoded
isAPrivateProgram: false with the variable/parameter (e.g., isAPrivateProgram)
so both project deletion sites mirror the same privacy-aware behavior as
deletedResourceDetails(), ensuring private projects tied to deleted
solutions/programs are matched and removed.

437-446: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix JSDoc type and parameter descriptions; clarify privacy-scoping intent for templates/tasks.

Three issues to address:

  1. JSDoc corrections needed:

    • isAPrivateProgram type should be {Boolean}, not {String}.
    • deletedBy description should read "User ID (or 'SYSTEM') that triggered the deletion; forwarded to the survey service" (not "Auth token").
    • Add @returns {Promise<Object>} documenting the aggregated deletion counts and success flag.
  2. Local DB filters (projectTemplateFilter, taskFilter) are scoped only by tenantId—they do not incorporate any privacy distinction. Note that isAPrivateProgram is forwarded to surveyService.deleteSolutionResource() but not used in your template/task deletion logic.

  3. Schema context: projectTemplates documents carry an isPrivate field (not isAPrivateProgram), and projectTemplateTasks documents do not include either field. Verify whether:

    • Templates and tasks should inherit privacy scoping from their parent program/solution (currently only tenant-scoped), or
    • The isAPrivateProgram parameter should be used in these filters if privacy separation is required at this layer (e.g., by cross-referencing with the program or solution record).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@module/admin/helper.js` around lines 437 - 446, Update the JSDoc on
deleteAssociatedResources: change isAPrivateProgram type to {Boolean}, change
deletedBy description to "User ID (or 'SYSTEM') that triggered the deletion;
forwarded to the survey service", and add `@returns` {Promise<Object>} describing
aggregated deletion counts and success flag. In the function body, ensure
projectTemplateFilter and taskFilter are adjusted to account for privacy
scoping: either add an isPrivate filter that matches isAPrivateProgram (or query
the parent program/solution to derive isPrivate) so templates/tasks are filtered
by privacy as well as tenantId, or explicitly document and enforce that privacy
is inherited from the program/solution before calling
surveyService.deleteSolutionResource; confirm use of projectTemplates.isPrivate
and that projectTemplateTasks currently have no privacy field and therefore must
be scoped via their parent template/solution lookup if required.
🧹 Nitpick comments (3)
module/admin/helper.js (2)

186-199: 💤 Low value

Collapse the duplicated programFilter branches.

Both branches are identical except for the boolean value, so the if/else is redundant.

♻️ Proposed simplification
-					let programFilter
-					if (isAPrivateProgram) {
-						programFilter = {
-							_id: resourceId,
-							tenantId: tenantId,
-							isAPrivateProgram: true,
-						}
-					} else {
-						programFilter = {
-							_id: resourceId,
-							tenantId: tenantId,
-							isAPrivateProgram: false,
-						}
-					}
+					const programFilter = {
+						_id: resourceId,
+						tenantId: tenantId,
+						isAPrivateProgram: Boolean(isAPrivateProgram),
+					}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@module/admin/helper.js` around lines 186 - 199, The if/else that builds
programFilter is duplicated; simplify by creating a single object and set the
boolean from isAPrivateProgram directly. Replace the conditional block that
assigns programFilter with one assignment using keys _id: resourceId, tenantId:
tenantId and isAPrivateProgram: isAPrivateProgram (or shorthand) so the logic
uses the existing resourceId/tenantId variables and removes the redundant
branches.

144-164: 💤 Low value

Realign the JSDoc with the new signature.

A few drift issues introduced/preserved while threading isAPrivateProgram through:

  • @param {Object} isAPrivateProgram should be {Boolean}.
  • userToken is still documented but it isn't part of the signature.
  • isAPrivateProgram = false is given a default while the params after it (tenantId, orgId) are required. Putting an optional in the middle is a footgun; consider moving it to the tail or making all callers pass it explicitly.
📝 Proposed JSDoc fix
- * `@param` {Object} isAPrivateProgram - If Program is Private `true` else `false`.
+ * `@param` {Boolean} isAPrivateProgram - `true` if the program is private, otherwise `false`.
   * `@param` {String} tenantId - Tenant identifier for multitenancy.
   * `@param` {String} orgId - Organization ID performing the operation.
   * `@param` {String} [deletedBy='SYSTEM'] - User ID or system name that triggered the deletion.
- * `@param` {String} userToken - Auth token used for downstream service calls (e.g., survey service).
   *
   * `@returns` {Promise<Object>} - Result object summarizing deletion impact.
   */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@module/admin/helper.js` around lines 144 - 164, The JSDoc for
deletedResourceDetails is out of sync: change `@param` {Object} isAPrivateProgram
to `@param` {Boolean} isAPrivateProgram, remove the undocumented userToken param
from the docblock, and fix the optional/default placement (either remove the
default and require callers to pass isAPrivateProgram explicitly or move
isAPrivateProgram to the end of the parameter list) so required params tenantId
and orgId are not after an optional; update the doc examples and description to
match the final signature of the deletedResourceDetails method.
generics/services/survey.js (1)

328-339: 💤 Low value

JSDoc is out of sync with the updated signature.

While editing this block to add isAPrivateProgram, please also realign the rest:

  • @param {String} isAPrivateProgram should be {Boolean} (callers pass true/false).
  • The block still documents token and solutionId, but the actual signature is (solutionIds, resourceType, tenantId, orgId, userId, isAPrivateProgram)token doesn't exist and solutionIds is plural.
  • userId is not documented at all.
📝 Proposed JSDoc fix
 /**
  * Calls the Survey Service to delete a survey or observation resource linked to a solution.
  *
- * `@param` {String} token - The user authentication token.
- * `@param` {String} solutionId - The ID of the solution (survey/observation) to be deleted.
+ * `@param` {Array<String>} solutionIds - IDs of the solutions (survey/observation) to be deleted.
  * `@param` {String} resourceType - Type of the resource being deleted ('solution', 'program', etc.).
  * `@param` {String} tenantId - Tenant identifier (used for multi-tenancy).
  * `@param` {String} orgId - Organization ID from where the deletion is triggered.
- * `@param` {String} isAPrivateProgram - If Program is Private `true` else `false`.
+ * `@param` {String} userId - User ID that triggered the deletion (used as `deletedBy`).
+ * `@param` {Boolean} isAPrivateProgram - `true` if the program is private, otherwise `false`.
  * `@returns` {Promise<Object>} - Result indicating success/failure and optional response data.
  */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@generics/services/survey.js` around lines 328 - 339, Update the JSDoc for
deleteSolutionResource to match the function signature: remove the obsolete
`token` and `solutionId` entries, document `solutionIds` (Array or String
depending on callers) instead of `solutionId`, add a `@param {String} userId`
entry, and change `@param {isAPrivateProgram}` type to `Boolean`; also update
the function description to reference deleting multiple solution(s) when
`solutionIds` is used and keep the other params (resourceType, tenantId, orgId)
accurate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@module/admin/helper.js`:
- Around line 267-276: The project deletion filter currently hardcodes the
isAPrivateProgram flag (projecFilter) which will skip private projects and leave
them orphaned; update the filter used before calling projectQueries.delete so it
uses the isAPrivateProgram parameter passed into deletedResourceDetails() (or
the surrounding function) instead of always false; locate the projecFilter
construction(s) and replace the hardcoded isAPrivateProgram: false with the
variable/parameter (e.g., isAPrivateProgram) so both project deletion sites
mirror the same privacy-aware behavior as deletedResourceDetails(), ensuring
private projects tied to deleted solutions/programs are matched and removed.
- Around line 437-446: Update the JSDoc on deleteAssociatedResources: change
isAPrivateProgram type to {Boolean}, change deletedBy description to "User ID
(or 'SYSTEM') that triggered the deletion; forwarded to the survey service", and
add `@returns` {Promise<Object>} describing aggregated deletion counts and success
flag. In the function body, ensure projectTemplateFilter and taskFilter are
adjusted to account for privacy scoping: either add an isPrivate filter that
matches isAPrivateProgram (or query the parent program/solution to derive
isPrivate) so templates/tasks are filtered by privacy as well as tenantId, or
explicitly document and enforce that privacy is inherited from the
program/solution before calling surveyService.deleteSolutionResource; confirm
use of projectTemplates.isPrivate and that projectTemplateTasks currently have
no privacy field and therefore must be scoped via their parent template/solution
lookup if required.

---

Nitpick comments:
In `@generics/services/survey.js`:
- Around line 328-339: Update the JSDoc for deleteSolutionResource to match the
function signature: remove the obsolete `token` and `solutionId` entries,
document `solutionIds` (Array or String depending on callers) instead of
`solutionId`, add a `@param {String} userId` entry, and change `@param
{isAPrivateProgram}` type to `Boolean`; also update the function description to
reference deleting multiple solution(s) when `solutionIds` is used and keep the
other params (resourceType, tenantId, orgId) accurate.

In `@module/admin/helper.js`:
- Around line 186-199: The if/else that builds programFilter is duplicated;
simplify by creating a single object and set the boolean from isAPrivateProgram
directly. Replace the conditional block that assigns programFilter with one
assignment using keys _id: resourceId, tenantId: tenantId and isAPrivateProgram:
isAPrivateProgram (or shorthand) so the logic uses the existing
resourceId/tenantId variables and removes the redundant branches.
- Around line 144-164: The JSDoc for deletedResourceDetails is out of sync:
change `@param` {Object} isAPrivateProgram to `@param` {Boolean} isAPrivateProgram,
remove the undocumented userToken param from the docblock, and fix the
optional/default placement (either remove the default and require callers to
pass isAPrivateProgram explicitly or move isAPrivateProgram to the end of the
parameter list) so required params tenantId and orgId are not after an optional;
update the doc examples and description to match the final signature of the
deletedResourceDetails method.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cdd74fea-5412-4827-a9bd-e60b108d0831

📥 Commits

Reviewing files that changed from the base of the PR and between 87d912b and 96d7e44.

📒 Files selected for processing (2)
  • generics/services/survey.js
  • module/admin/helper.js

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.

1 participant