Skip to content

feat: Implemented GET /analytics/yield-breakdown Specific Interest Extraction#456

Open
Ugasutun wants to merge 1 commit intoDevsol-01:mainfrom
Ugasutun:feature/yield-breakdown-analytics
Open

feat: Implemented GET /analytics/yield-breakdown Specific Interest Extraction#456
Ugasutun wants to merge 1 commit intoDevsol-01:mainfrom
Ugasutun:feature/yield-breakdown-analytics

Conversation

@Ugasutun
Copy link
Copy Markdown

Closes #413

PR Description - Issue #413: GET /analytics/yield-breakdown Specific Interest Extraction

Summary

Implements a yield breakdown endpoint that displays exact dollar amounts mapped to individual savings pools, allowing users to know exactly where they're making money from yield.

Background & Context

  • Issue: [Backend] GET /analytics/yield-breakdown Specific Interest Extraction #413 - [Backend] GET /analytics/yield-breakdown Specific Interest Extraction
  • Purpose: Displays exact dollar amounts mapped to individual savings pools so the user knows where they're making money.
  • Acceptance Criteria:
    • Query Transaction table where: { userId, type: 'YIELD' }
    • Sum amount total → totalInterestEarned
    • Group by poolId isolating progress outputs ({ pool: 'XLM Staking', earned: 420.50 })

Changes Made

Files Modified:

  1. backend/src/modules/analytics/analytics.service.ts

    • Added getYieldBreakdown(userId: string) method (lines 217-255)
    • Queries YIELD transactions for the user
    • Groups by poolId and sums amounts
    • Maps pool IDs to human-readable names
  2. backend/src/modules/analytics/analytics.controller.ts

    • Added GET /analytics/yield-breakdown endpoint (lines 82-98)
    • Protected with JWT authentication
    • Returns YieldBreakdownDto
  3. backend/src/modules/analytics/dto/yield-breakdown.dto.ts

    • Defines response structure:
      {
        pools: Array<{ pool: string; earned: number }>;
        totalInterestEarned: number;
      }
  4. backend/src/modules/analytics/analytics.service.yield.spec.ts

    • Added unit tests for yield breakdown functionality
    • Tests grouping by pool and total calculation

Implementation Details

Service Method: getYieldBreakdown(userId: string)

// Queries Transaction table (where: { userId, type: 'YIELD' })
const yieldTransactions = await this.transactionRepository.find({
  where: { userId, type: LedgerTransactionType.YIELD },
});

// Sums amount total → totalInterestEarned
// Groups by poolId isolating progress outputs ({ pool: 'XLM Staking', earned: 420.50 })

Example Response:

{
  "pools": [
    { "pool": "XLM Staking", "earned": 495.5 },
    { "pool": "AQUA Farming", "earned": 150.25 }
  ],
  "totalInterestEarned": 645.75
}

Testing

  • Unit tests in analytics.service.yield.spec.ts pass successfully
  • Tests verify:
    • Pool grouping works correctly
    • Amounts are properly summed
    • Empty results return empty pools array with 0 total

Checklist

  • Queries Transaction table filtering by userId and type: 'YIELD'
  • Calculates totalInterestEarned from sum of all yields
  • Groups yields by poolId
  • Maps pool IDs to human-readable names
  • Returns sorted pools array (highest earned first)
  • Endpoint protected with JWT auth
  • Unit tests pass

Target Branch

  • Branch: feature/yield-breakdown-analytics
  • Target: main

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nestera Ready Ready Preview, Comment Mar 27, 2026 9:48pm

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.

[Backend] GET /analytics/yield-breakdown Specific Interest Extraction

1 participant