Skip to content

feat(transactions): implement sync, categorization, and history in TransactionsService - #116

Merged
Uyoxy merged 2 commits into
stellarspend:mainfrom
coderDom-x:feat/108-transactions-service
Aug 24, 2026
Merged

feat(transactions): implement sync, categorization, and history in TransactionsService#116
Uyoxy merged 2 commits into
stellarspend:mainfrom
coderDom-x:feat/108-transactions-service

Conversation

@coderDom-x

@coderDom-x coderDom-x commented Aug 24, 2026

Copy link
Copy Markdown
Contributor
code ## Summary Implements the four core `TransactionsService` methods per #108: `syncTransactions`, `getHistory`, `categorize`, and `getSpendingByCategory`. Horizon integration uses `@stellar/stellar-sdk`'s `Horizon.Server`, matching the pattern already established in `BlockchainService`.

Changes

  • syncTransactions(userId, publicKey): fetches the last 200 Horizon operations, filters to payment-type ops, normalizes into TransactionEntity rows, inserts via ON CONFLICT (hash) DO NOTHING, returns the count of rows actually inserted (via RETURNING, so duplicates aren't counted)
  • getHistory(userId, options): paginated query with optional category/asset filters, ordered newest-first
  • categorize(userId, transactionId, category): updates category on a single row; throws NotFoundException if missing, ForbiddenException if it belongs to another user
  • getSpendingByCategory(userId, asset, since): aggregated totals per category
  • Unit tests in transactions.service.spec.ts covering sync deduplication (including repeat-call idempotency), pagination, category ownership checks, and aggregation

Not included in this PR

  • TransactionsController wiring with JwtAuthGuard
  • transactions.module.ts TypeORM wiring
  • New index migration (add-transactions-indexes.ts)

These remain open scope items from #108 — this PR covers the service layer only. Will follow up separately / update if handling the rest in this same branch.

Testing

…regation

- syncTransactions: fetch last 200 Horizon ops, normalize payments,
  insert with ON CONFLICT (hash) DO NOTHING, return new-row count
- getHistory: paginated query with optional category/asset filters
- categorize: updates category, enforces userId ownership (403/404)
- getSpendingByCategory: aggregated totals grouped by category
- Fix Horizon SDK import to use @stellar/stellar-sdk Horizon.Server,
  matching BlockchainService
- Add unit tests covering dedup, pagination, ownership checks, aggregation

Refs stellarspend#108
@Uyoxy

Uyoxy commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Nice work — this fully closes out #108. Went through each acceptance
criterion:

  • syncTransactions: ON CONFLICT dedup verified, including the
    "run twice, no duplicate rows" test case
  • getHistory: pagination + category/asset filters
  • categorize: correct 403/404 ownership handling
  • getSpendingByCategory: aggregation query
  • ✅ Controller wired with JwtAuthGuard on all four routes
  • ✅ Module updated for TypeORM
  • ✅ Index migration present for (user_id, created_at DESC) and
    (user_id, category)
  • ✅ Unit tests cover sync dedup, pagination, ownership, aggregation
    please fix ci issues so i can merge

…regation

- syncTransactions: fetch last 200 Horizon ops, normalize payments,
  insert with ON CONFLICT (hash) DO NOTHING, return new-row count
- getHistory: paginated query with optional category/asset filters
- categorize: updates category, enforces userId ownership (403/404)
- getSpendingByCategory: aggregated totals grouped by category
- Fix Horizon SDK import to use @stellar/stellar-sdk Horizon.Server,
  matching BlockchainService
- Add unit tests covering dedup, pagination, ownership checks, aggregation

Refs stellarspend#108
@Uyoxy

Uyoxy commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

great

@Uyoxy
Uyoxy merged commit 7c7e8b3 into stellarspend:main Aug 24, 2026
1 check 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.

Implement transaction sync, categorization, and history in TransactionsService

2 participants