Files
GearBox/src/server/mcp/resources/collection.ts
Jean-Luc Makiola 4f434f39bf
All checks were successful
CI / ci (push) Successful in 33s
fix: replace @/ path alias with relative imports in MCP server
The @/ alias resolves via tsconfig but not in production where
Bun runs server files directly. Use relative paths instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 14:22:23 +02:00

42 lines
1.3 KiB
TypeScript

import type { db as prodDb } from "../../../db/index.ts";
import { getAllCategories } from "../../services/category.service.ts";
import { getAllItems } from "../../services/item.service.ts";
import { getAllSetups } from "../../services/setup.service.ts";
import { getAllThreads } from "../../services/thread.service.ts";
import { getGlobalTotals } from "../../services/totals.service.ts";
type Db = typeof prodDb;
export function getCollectionSummary(db: Db) {
const totals = getGlobalTotals(db);
const categories = getAllCategories(db);
const items = getAllItems(db);
const setups = getAllSetups(db);
const activeThreads = getAllThreads(db, false);
// Build items-by-category map
const itemsByCategory: Record<string, number> = {};
for (const item of items) {
const catName = item.categoryName;
itemsByCategory[catName] = (itemsByCategory[catName] ?? 0) + 1;
}
return {
overview: {
totalItems: totals?.itemCount ?? 0,
totalWeightGrams: totals?.totalWeight ?? 0,
totalCostCents: totals?.totalCost ?? 0,
categoryCount: categories.length,
setupCount: setups.length,
activeThreadCount: activeThreads.length,
},
itemsByCategory,
activeThreads: activeThreads.map((t) => ({
id: t.id,
name: t.name,
candidateCount: t.candidateCount,
category: t.categoryName,
})),
};
}