Skip to content

Created new function For referral users status count export report#770

Open
Tusharmahajan12 wants to merge 5 commits into
tekdi:aspire-leadersfrom
Tusharmahajan12:new_asp_apr24
Open

Created new function For referral users status count export report#770
Tusharmahajan12 wants to merge 5 commits into
tekdi:aspire-leadersfrom
Tusharmahajan12:new_asp_apr24

Conversation

@Tusharmahajan12

@Tusharmahajan12 Tusharmahajan12 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Introduced a new referral summary endpoint providing aggregated referral metrics including active and registered user counts, along with cohort-scoped application stage data for comprehensive referral analytics.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new referral summary endpoint (POST report/summary) to retrieve aggregated status counts per referral entity. Feedback highlights two critical issues: first, the new getReferralSummary method lacks pagination support, which could lead to performance degradation or OOM errors; second, changing the join type to LEFT JOIN globally in buildReportBase breaks the existing user-centric getReferralReport endpoint by returning empty user records. It is recommended to implement pagination for the summary endpoint and conditionally apply the LEFT JOIN using an internal flag.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/referrals/referrals.service.ts
Comment thread src/referrals/referrals.service.ts Outdated
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

More reviews will be available in 29 minutes and 40 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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

🚦 How do rate limits work?

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

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d2d92422-e220-4355-a192-702cfd65a243

📥 Commits

Reviewing files that changed from the base of the PR and between 76e50c0 and ae0798f.

📒 Files selected for processing (1)
  • src/referrals/referrals.service.ts

Walkthrough

Adds a POST /referrals/report/summary endpoint with a new REFERRAL_SUMMARY API ID and response message. The endpoint delegates to a new getReferralSummary service method that aggregates per-referral active/registered counts and cohort membership stage counts. buildReportBase gains a useLeftJoin flag, and getReferralReport is updated to use LEFT JOIN, distinct user counting, and conditional cohort membership scoping.

Changes

Referral Summary Endpoint

Layer / File(s) Summary
API ID and response message constants
src/common/utils/api-id.config.ts, src/common/utils/response.messages.ts
Adds REFERRAL_SUMMARY to APIID and REFERRAL_SUMMARY_SUCCESS to API_RESPONSES.
POST /referrals/report/summary controller endpoint
src/referrals/referrals.controller.ts
Adds getSummary method to ReferralsController routing POST report/summary, applying AllExceptionsFilter and ValidationPipe, delegating to referralsService.getReferralSummary(dto), and returning via APIResponse.success.
buildReportBase LEFT JOIN parameter
src/referrals/referrals.service.ts
Extends buildReportBase with a useLeftJoin flag switching the FROM/join strategy between LEFT JOIN from ReferralEntities and inner JOIN from UserAttribution.
getReferralReport SQL and cohort membership changes
src/referrals/referrals.service.ts
getReferralReport now calls buildReportBase with useLeftJoin=true, orders by ua."createdAt" DESC NULLS LAST, counts DISTINCT ua."userId", filters null userIds from cohort membership queries, and conditionally scopes by cohortIds.
getReferralSummary service method
src/referrals/referrals.service.ts
Adds getReferralSummary which uses buildReportBase for filtering, executes paginated count and grouped aggregate SQL for per-referral active/registered counts, fetches cohort membership stage counts for returned referral ids, and merges cohort aggregates into each summary row.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • tekdi/user-microservice#741: This PR extends the referral reporting feature introduced there by adding the /report/summary endpoint and modifying the existing getReferralReport/buildReportBase SQL.
  • tekdi/user-microservice#750: Both PRs modify referral aggregate counting logic inside referrals.service.ts, with overlapping changes to how user counts and active status are computed.

Suggested reviewers

  • mahajanmahesh935
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'referral users status count export report' but the PR primarily adds a new getReferralSummary() endpoint and updates related configuration, which is broader than just an 'export report' function. Consider a more accurate title like 'Add referral summary endpoint with aggregate counts' to better reflect the main changes (new endpoint, service method, and API configuration).
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

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

🤖 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/referrals/referrals.controller.ts`:
- Around line 133-137: The getSummary method in the referrals.controller.ts file
has Prettier formatting violations on lines 133, 136, and 137. Reformat the
method decorator block and method signature to comply with Prettier's line
length and formatting rules. The long description string in the ApiOkResponse
decorator on line 136 and the lengthy method signature with multiple parameters
on line 137 need to be reformatted, likely by breaking them across multiple
lines with appropriate indentation to stay within the configured line length
limit.

In `@src/referrals/referrals.service.ts`:
- Line 460: The changed lines in the referrals service contain Prettier
formatting violations that are being flagged by ESLint. Run Prettier on the
referrals.service.ts file to automatically format the code according to the
project's Prettier configuration. This includes the buildReportBase method call
on line 460 and the other specified lines (513, 553-557, 600, 623, 627, 642,
653, 656) which will be automatically reformatted to comply with Prettier
standards.
- Around line 570-576: The correlated subquery that selects tags using
ARRAY(SELECT DISTINCT UNNEST(u2."auto_tags") ...) from UserAttribution ua2 and
Users u2 is not applying the same cohort filter as the main aggregate query.
When filters.cohortIds is provided, add the equivalent cohort constraint to the
WHERE clause of this subquery to ensure tags are only collected from users
within the specified cohort, matching the scoping of the counts in the main
query.
- Line 486: The countSql query uses COUNT(*) which counts all rows including
duplicates and unattributed rows, causing the totalCount and hasMore values to
drift from the expected distinct user-count behavior. Replace COUNT(*) with
COUNT(DISTINCT user_id) in the countSql variable to ensure the count reflects
the actual number of distinct users rather than the total number of referral
rows.
🪄 Autofix (Beta)

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

Run ID: e3cbdb9e-411e-47e5-8888-abc2d881b6dc

📥 Commits

Reviewing files that changed from the base of the PR and between 6c4be94 and 76e50c0.

📒 Files selected for processing (4)
  • src/common/utils/api-id.config.ts
  • src/common/utils/response.messages.ts
  • src/referrals/referrals.controller.ts
  • src/referrals/referrals.service.ts

Comment thread src/referrals/referrals.controller.ts
Comment thread src/referrals/referrals.service.ts Outdated
Comment thread src/referrals/referrals.service.ts Outdated
Comment thread src/referrals/referrals.service.ts Outdated
@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