Skip to main content
Glama
transaction-grouper.ts1.37 kB
// Groups transactions by category and aggregates spending import type { Transaction, CategorySpending, CategoryGroupInfo } from '../types/domain.js'; export class TransactionGrouper { groupByCategory( transactions: Transaction[], getCategoryName: (categoryId: string) => string, getGroupInfo: (categoryId: string) => CategoryGroupInfo | undefined, includeIncome: boolean ): Record<string, CategorySpending> { const spendingByCategory: Record<string, CategorySpending> = {}; transactions.forEach((transaction) => { if (!transaction.category) return; // Skip uncategorized const categoryId = transaction.category; const categoryName = getCategoryName(categoryId); const group = getGroupInfo(categoryId) || { name: 'Unknown Group', isIncome: false, }; // Skip income categories if not requested if (group.isIncome && !includeIncome) return; if (!spendingByCategory[categoryId]) { spendingByCategory[categoryId] = { id: categoryId, name: categoryName, group: group.name, isIncome: group.isIncome, total: 0, transactions: 0, }; } spendingByCategory[categoryId].total += transaction.amount; spendingByCategory[categoryId].transactions += 1; }); return spendingByCategory; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/s-stefanov/actual-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server