Skip to content

Streaming Audit Export GET /transactions/export#432

Merged
Devsol-01 merged 8 commits intoDevsol-01:mainfrom
OthmanImam:feat/Streaming
Mar 26, 2026
Merged

Streaming Audit Export GET /transactions/export#432
Devsol-01 merged 8 commits intoDevsol-01:mainfrom
OthmanImam:feat/Streaming

Conversation

@OthmanImam
Copy link
Copy Markdown
Contributor

Closes: #309

Summary

  • Implemented a streaming CSV export endpoint: GET /transactions/export.
  • Enables user audit downloads using Node Streams and CSV generation.
  • Uses @fast-csv/format for incremental CSV row writing.
  • Query filtering uses existing TransactionQueryDto conditions and increments with pagination settings to avoid large memory peaks.

Functional behavior

  • Stream rows from database in batches (limit / skip) using same query builder logic.
  • Dynamic transformation to CSV row with:
    • id, userId, type, amount, formatted amount, publicKey, eventId, transactionHash, ledgerSequence, poolId, assetId, metadata, createdAt
  • Sets CSV response headers:
    • Content-Type: text/csv
    • Content-Disposition: attachment; filename="nestera_history.csv"

Files Changed

  • backend/src/modules/transactions/transactions.controller.ts
  • backend/src/modules/transactions/transactions.service.ts
  • backend/package.json
  • backend/pnpm-lock.yaml

Validation

  • npm run build passes
  • Endpoint stream path tested manually via authentication and query parameters
  • Existing transactions list API unchanged

…lorer links

- Add TransactionFormattingInterceptor for global response formatting
- Format amounts with proper precision and currency symbols
- Generate Stellar Expert explorer links for transactions and assets
- Update transaction DTO and module configuration
- Include PR documentation in interceptor README
…matting and explorer links

## Summary

Implemented transaction response enrichment interceptor that formats raw database amounts into user-friendly displays and adds Stellar Expert exploration links.

## Changes

- **New Interceptor**: `TransactionFormattingInterceptor` in `common/interceptors/`
  - Formats amounts: `"100000000"` → `"$100.00"` with proper USDC precision (7 decimals)
  - Generates Stellar Expert links from transaction hashes
  - Configurable asset mapping system

- **Module Updates**:
  - `transactions.module.ts`: Added global interceptor provider
  - `transaction-response.dto.ts`: Added `amountFormatted` and `explorerLinks` fields
  - `transactions.service.ts`: Added asset ID extraction logic

## Acceptance Criteria ✅

- ✅ Construct explicit formatter logic attaching asset mapping symbols
- ✅ Evaluate Stellar contract precision parameters intelligently
- ✅ Render UI outputs exactly (e.g., `amountFormatted.display: "$500.00"`)
- ✅ Dynamically attach canonical Stellar Expert exploration links

## Files Changed

- `backend/src/common/interceptors/transaction-formatting.interceptor.ts` (new)
- `backend/src/modules/transactions/transactions.module.ts`
- `backend/src/modules/transactions/dto/transaction-response.dto.ts`
- `backend/src/modules/transactions/transactions.service.ts`
- `backend/src/common/interceptors/TRANSACTION_FORMATTING_README.md` (new)

## Testing

- ✅ `npm run build` passes
- ✅ TypeScript compilation successful
- ✅ Interceptor integration verified
- Add amountFormatted and assetId fields to TransactionResponseDto mock
- Fix ESLint error in transaction-formatting.interceptor.ts (use Object.hasOwn)
- Resolves TypeScript compilation error in transactions.controller.spec.ts
- Ensures CI tests pass after transaction enrichment implementation
- Add RolesGuard and @roles decorators to admin.controller.ts
- Enforce ADMIN role requirement for KYC management endpoints
- Complement existing JwtAuthGuard with role-based authorization
- AdminSavingsController already properly protected with RBAC
- User entity already has role column (USER/ADMIN) with proper defaults

Acceptance Criteria:
✅ Create a RolesGuard complementing the JwtAuthGuard
✅ Expose @roles('ADMIN') decorators for sensitive endpoints
✅ Add role column (USER/ADMIN) to the existing User TypeORM entity

Tests: ✅ RBAC tests passing
- New endpoint GET /transactions/export in TransactionsController
- Streams query-filtered transaction data by chunk to keep memory usage low
- Uses @fast-csv/format for reliable CSV generation
- Response headers set: Content-Type and Content-Disposition
- Includes CSV-ready fields with safe metadata JSON fallback
- Keeps existing pagination/query behavior in service query builder
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

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

Project Deployment Actions Updated (UTC)
nestera Ready Ready Preview, Comment Mar 26, 2026 11:42pm

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@OthmanImam Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Devsol-01 Devsol-01 merged commit bc0ccfb into Devsol-01:main Mar 26, 2026
4 checks passed
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] Streaming Audit Export GET /transactions/export

2 participants