actual-mcp
Version:
Actual Budget MCP server exposing API functionality
32 lines • 1.27 kB
JavaScript
export class TransactionGrouper {
groupByCategory(transactions, getCategoryName, getGroupInfo, includeIncome) {
const spendingByCategory = {};
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;
}
}
//# sourceMappingURL=transaction-grouper.js.map