Skip to content

Task#0000 Changes For Hidden Country Field - #796

Open
Tusharmahajan12 wants to merge 6 commits into
tekdi:aspire-leadersfrom
Tusharmahajan12:new_aspaug10
Open

Task#0000 Changes For Hidden Country Field#796
Tusharmahajan12 wants to merge 6 commits into
tekdi:aspire-leadersfrom
Tusharmahajan12:new_aspaug10

Conversation

@Tusharmahajan12

@Tusharmahajan12 Tusharmahajan12 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added filtered cohort-member reporting by cohort and user IDs, with authentication and Regional Admin country restrictions.
    • Cohort memberships now retain the user’s resolved country when created individually or in bulk.
    • Added country listing with name and active-status filters, pagination, sorting, and field selection.
    • Added request validation for UUIDs, pagination limits, and report inputs.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Tusharmahajan12, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 51e0a1b2-c1e2-4bba-8111-b3b6dcc06325

📥 Commits

Reviewing files that changed from the base of the PR and between df9e300 and c9b4eea.

📒 Files selected for processing (1)
  • src/adapters/postgres/cohortMembers-adapter.ts

Walkthrough

The pull request adds cohort-member country snapshots and a role-scoped report-filter endpoint. It also adds an Aspire Leaders-specific country-list API with validation, filtering, pagination, repository integration, and application-module wiring.

Changes

Cohort-member reporting

Layer / File(s) Summary
Reporting contracts and snapshot data
src/cohortMembers/dto/..., src/cohortMembers/entities/..., src/adapters/cohortMembersservicelocator.ts, src/common/utils/*
Adds the report filter DTO, service contract, nullable country snapshot field, API identifier, and success message.
Membership country resolution
src/adapters/postgres/cohortMembers-adapter.ts
Resolves country IDs during single and bulk membership creation and stores them on new memberships.
Authenticated role-scoped reporting
src/cohortMembers/cohortMembers.controller.ts, src/adapters/postgres/cohortMembers-adapter.ts
Adds the authenticated report-filter route and applies cohort, user, role, and Regional Admin country filtering.

Aspire Leaders country listing

Layer / File(s) Summary
Country-list query contract
src/aspire-leaders-specific/dto/...
Adds validated pagination, name, and active-status query parameters with a maximum limit of 500.
Country-list service workflow
src/aspire-leaders-specific/aspire-leaders-specific.service.ts, src/common/utils/response.messages.ts
Adds repository-backed filtering, sorting, field selection, pagination, counts, and standardized responses.
Country-list endpoint wiring
src/aspire-leaders-specific/aspire-leaders-specific.controller.ts, src/aspire-leaders-specific/aspire-leaders-specific.module.ts, src/app.module.ts, src/common/utils/api-id.config.ts
Registers the module and exposes the documented country-list endpoint.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CohortMembersController
  participant PostgresCohortMembersService
  participant UserAndCountryData
  participant CohortMembers
  CohortMembersController->>PostgresCohortMembersService: Submit validated cohort and user filters
  PostgresCohortMembersService->>UserAndCountryData: Resolve caller role and Regional Admin country IDs
  PostgresCohortMembersService->>CohortMembers: Query permitted cohort members
  CohortMembers-->>PostgresCohortMembersService: Return filtered records
  PostgresCohortMembersService-->>CohortMembersController: Return standardized response
Loading
sequenceDiagram
  participant Client
  participant AspireLeadersSpecificController
  participant AspireLeadersSpecificService
  participant CountryRepository
  Client->>AspireLeadersSpecificController: Submit country-list query
  AspireLeadersSpecificController->>AspireLeadersSpecificService: Pass validated query
  AspireLeadersSpecificService->>CountryRepository: Query filtered countries and count
  CountryRepository-->>AspireLeadersSpecificService: Return countries and count
  AspireLeadersSpecificService-->>AspireLeadersSpecificController: Return standardized response
  AspireLeadersSpecificController-->>Client: Return HTTP 200 response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title identifies the country-field change, which is a central part of the pull request.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 8

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

Inline comments:
In `@src/app.module.ts`:
- Line 99: Update the module inventory array used by onModuleInit to include
AspireLeadersSpecificModule, keeping the existing “all loaded modules” claim
accurate.

In `@src/aspire-leaders-specific/aspire-leaders-specific.controller.ts`:
- Around line 34-38: Update the OpenAPI metadata in
AspireLeadersSpecificController: change the list-countries description to state
a default limit of 500, and update the successful-response example to use limit:
500. Apply both changes in
src/aspire-leaders-specific/aspire-leaders-specific.controller.ts at lines 34-38
and 70-91.

In `@src/aspire-leaders-specific/dto/list-countries.dto.ts`:
- Around line 1-11: Run the configured Prettier formatter on the modified
imports and code in src/aspire-leaders-specific/dto/list-countries.dto.ts (lines
1-11), src/aspire-leaders-specific/aspire-leaders-specific.service.ts (lines
1-14), src/aspire-leaders-specific/aspire-leaders-specific.controller.ts (lines
10-23), src/aspire-leaders-specific/aspire-leaders-specific.module.ts (lines
1-5), and src/app.module.ts (line 39). Ensure formatting uses double quotes and
removes trailing commas according to the project configuration; no behavioral
changes are needed.
- Around line 62-65: Update the boolean query-property decorators in the
countries list DTO around `@Type`(() => Boolean) so string values are parsed
explicitly: map "true" and "false" to their corresponding booleans instead of
relying on JavaScript truthiness, while preserving optional and boolean
validation behavior.

In `@src/cohortMembers/cohortMembers.controller.ts`:
- Around line 217-237: Update reportFilterCohortMembers in
src/cohortMembers/cohortMembers.controller.ts:217-237 to obtain the caller ID
from the authenticated principal or signed service identity instead of the
userId query parameter, and reject missing, unknown, deleted, or non-admin roles
before invoking the adapter. Update the corresponding reportFilterCohortMembers
implementation in src/adapters/postgres/cohortMembers-adapter.ts:7020-7048 to
fail closed for any unrecognized or non-Regional-Admin role, preventing
unrestricted cohortId plus userId filtering.

In `@src/cohortMembers/dto/cohortMembers-report-filter.dto.ts`:
- Around line 1-31: Apply the repository Prettier configuration to the changed
TypeScript code. In src/cohortMembers/dto/cohortMembers-report-filter.dto.ts
lines 1-31, format imports, Swagger strings, and the UUID version string; in
src/adapters/cohortMembersservicelocator.ts line 4, format the DTO import; in
src/cohortMembers/entities/cohort-member.entity.ts line 73, format TypeORM
column options; in src/adapters/postgres/cohortMembers-adapter.ts lines
6954-7021, format changed string literals; and in
src/cohortMembers/cohortMembers.controller.ts lines 32-230, format the DTO
import and endpoint strings.
- Line 19: Update the UUID example in the cohort members report filter DTO to
use a valid UUIDv4 with a valid variant, replacing the current version-2 example
while preserving the existing API example metadata.

In `@src/cohortMembers/entities/cohort-member.entity.ts`:
- Around line 73-74: Add a deployment migration that backfills
user_cohort_country_id for existing CohortMembers using available historical
country-at-insertion data, and document the fallback behavior when that data
cannot be recovered. Ensure reportFilterCohortMembers continues including
applicable historical rows rather than omitting null snapshots, while preserving
the nullable column for records without a reliable country value.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 147823ee-b98c-47bc-8895-8964cbdce290

📥 Commits

Reviewing files that changed from the base of the PR and between 2ac11c0 and 4867116.

📒 Files selected for processing (12)
  • src/adapters/cohortMembersservicelocator.ts
  • src/adapters/postgres/cohortMembers-adapter.ts
  • src/app.module.ts
  • src/aspire-leaders-specific/aspire-leaders-specific.controller.ts
  • src/aspire-leaders-specific/aspire-leaders-specific.module.ts
  • src/aspire-leaders-specific/aspire-leaders-specific.service.ts
  • src/aspire-leaders-specific/dto/list-countries.dto.ts
  • src/cohortMembers/cohortMembers.controller.ts
  • src/cohortMembers/dto/cohortMembers-report-filter.dto.ts
  • src/cohortMembers/entities/cohort-member.entity.ts
  • src/common/utils/api-id.config.ts
  • src/common/utils/response.messages.ts

Comment thread src/app.module.ts
Comment thread src/aspire-leaders-specific/aspire-leaders-specific.controller.ts
Comment thread src/aspire-leaders-specific/dto/list-countries.dto.ts Outdated
Comment thread src/aspire-leaders-specific/dto/list-countries.dto.ts
Comment thread src/cohortMembers/cohortMembers.controller.ts
Comment thread src/cohortMembers/dto/cohortMembers-report-filter.dto.ts
Comment thread src/cohortMembers/dto/cohortMembers-report-filter.dto.ts Outdated
Comment thread src/cohortMembers/entities/cohort-member.entity.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
src/adapters/postgres/cohortMembers-adapter.ts (2)

2527-2544: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Backfill country snapshots for existing cohort memberships.

These assignments only populate new rows. Existing rows, including rows updated through the existingMember path, retain userCohortCountryId = NULL. Line 7052 then excludes those members from Regional Admin reports, even when their country is allowed.

Add a one-time migration that fills null snapshots before this report filter is enabled. Only populate a null snapshot during later updates; do not overwrite an existing snapshot.

🤖 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 `@src/adapters/postgres/cohortMembers-adapter.ts` around lines 2527 - 2544, Add
a one-time migration to backfill userCohortCountryId for existing cohort
memberships where the snapshot is null, resolving each member’s country through
resolveUserCohortCountryId and preserving any non-null snapshot. Update the
existingMember path to populate only null snapshots during later updates,
without overwriting existing values, before the Regional Admin report filter at
line 7052 is enabled.

7027-7028: 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Derive report scope from all assigned roles.

getFirstRoleName() orders roles by UserTenantMapping.Id and returns one role. A user with both Admin and Regional Admin roles can pass as Regional Admin when that row returns first, and see only countries they should not. Query the assigned roles on this path and apply explicit precedence: Admin has global access; Regional Admin without Admin stays country-scoped.

🤖 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 `@src/adapters/postgres/cohortMembers-adapter.ts` around lines 7027 - 7028,
Update the report-scope logic around getFirstRoleName in the cohort-members
adapter to query all roles assigned to adminUserId instead of relying on a
single first role. Apply explicit precedence so any Admin role grants global
access, while Regional Admin only grants country-scoped access when Admin is
absent; preserve the existing scope behavior for other roles.
🤖 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.

Inline comments:
In `@src/adapters/postgres/cohortMembers-adapter.ts`:
- Line 6990: Reformat the assignment to remaining in the cohort-members adapter
so it conforms to the repository’s Prettier style and passes formatting checks,
without changing its behavior.

---

Outside diff comments:
In `@src/adapters/postgres/cohortMembers-adapter.ts`:
- Around line 2527-2544: Add a one-time migration to backfill
userCohortCountryId for existing cohort memberships where the snapshot is null,
resolving each member’s country through resolveUserCohortCountryId and
preserving any non-null snapshot. Update the existingMember path to populate
only null snapshots during later updates, without overwriting existing values,
before the Regional Admin report filter at line 7052 is enabled.
- Around line 7027-7028: Update the report-scope logic around getFirstRoleName
in the cohort-members adapter to query all roles assigned to adminUserId instead
of relying on a single first role. Apply explicit precedence so any Admin role
grants global access, while Regional Admin only grants country-scoped access
when Admin is absent; preserve the existing scope behavior for other roles.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d3c9deb3-99d4-4d36-8224-5c0b1eab16e4

📥 Commits

Reviewing files that changed from the base of the PR and between 4867116 and 2a0bc79.

📒 Files selected for processing (1)
  • src/adapters/postgres/cohortMembers-adapter.ts

Comment thread src/adapters/postgres/cohortMembers-adapter.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (2)
src/adapters/postgres/cohortMembers-adapter.ts (2)

2532-2537: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

Cache the country ID for each user during bulk creation.

resolveUserCohortCountryId(userId) runs inside the cohortId loop. A request that adds one user to multiple cohorts repeats the same database join for each cohort.

Resolve once per userId after user validation. Reuse the value for each new membership.

As per path instructions, review TypeScript code for best practices recommended for performance.

🤖 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 `@src/adapters/postgres/cohortMembers-adapter.ts` around lines 2532 - 2537,
Move the resolveUserCohortCountryId call out of the cohortId loop and execute it
once per validated user in the bulk-creation flow. Cache the result in the
user-level scope, then reuse that value when creating every membership for the
user while preserving the existing insert behavior.

Source: Path instructions


7066-7084: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Backfill historical country snapshots before enabling Regional Admin filtering.

Existing memberships can have user_cohort_country_id = NULL, and In(allowedCountryIds) excludes them. Add a deployment backfill with an explicit historical-data policy. Do not fall back to live Users.country.

🤖 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 `@src/adapters/postgres/cohortMembers-adapter.ts` around lines 7066 - 7084,
Before enabling the Regional Admin filter in the query flow around
resolveRegionalAdminCountryIds, add a deployment backfill that populates NULL
user_cohort_country_id values from the intended historical snapshot source.
Define and apply an explicit policy for records whose historical country cannot
be resolved, and ensure the filtering logic uses only persisted cohort-country
snapshots—not live Users.country.
🤖 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.

Inline comments:
In `@src/cohortMembers/cohortMembers.controller.ts`:
- Around line 226-229: Update the Swagger setup in main.ts to register the
access-token scheme with addBearerAuth, then replace ApiBasicAuth with
ApiBearerAuth('access-token') on the report-filter endpoint protected by
JwtAuthGuard.

---

Outside diff comments:
In `@src/adapters/postgres/cohortMembers-adapter.ts`:
- Around line 2532-2537: Move the resolveUserCohortCountryId call out of the
cohortId loop and execute it once per validated user in the bulk-creation flow.
Cache the result in the user-level scope, then reuse that value when creating
every membership for the user while preserving the existing insert behavior.
- Around line 7066-7084: Before enabling the Regional Admin filter in the query
flow around resolveRegionalAdminCountryIds, add a deployment backfill that
populates NULL user_cohort_country_id values from the intended historical
snapshot source. Define and apply an explicit policy for records whose
historical country cannot be resolved, and ensure the filtering logic uses only
persisted cohort-country snapshots—not live Users.country.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 352b4662-efaa-403c-8e55-813bef5f9a31

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0bc79 and df9e300.

📒 Files selected for processing (6)
  • src/adapters/postgres/cohortMembers-adapter.ts
  • src/app.module.ts
  • src/aspire-leaders-specific/aspire-leaders-specific.controller.ts
  • src/aspire-leaders-specific/dto/list-countries.dto.ts
  • src/cohortMembers/cohortMembers.controller.ts
  • src/cohortMembers/dto/cohortMembers-report-filter.dto.ts

Comment thread src/cohortMembers/cohortMembers.controller.ts
@sonarqubecloud

Copy link
Copy Markdown

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