feat(14-03): convert core data services to async PostgreSQL operations

- item.service.ts: 6 functions async, removed .all()/.get()/.run()
- category.service.ts: 4 functions async, transaction uses async callback
- thread.service.ts: 10 functions async, transactions in resolveThread/reorderCandidates use async callbacks
- setup.service.ts: 8 functions async, syncSetupItems transaction uses async callback
- totals.service.ts: 2 functions async, removed .all()/.get()
This commit is contained in:
2026-04-04 12:32:58 +02:00
parent 295be8c09d
commit 4d705af3f1
5 changed files with 184 additions and 193 deletions

View File

@@ -4,7 +4,7 @@ import { categories, items } from "../../db/schema.ts";
type Db = typeof prodDb;
export function getCategoryTotals(db: Db = prodDb) {
export async function getCategoryTotals(db: Db = prodDb) {
return db
.select({
categoryId: items.categoryId,
@@ -16,17 +16,17 @@ export function getCategoryTotals(db: Db = prodDb) {
})
.from(items)
.innerJoin(categories, eq(items.categoryId, categories.id))
.groupBy(items.categoryId)
.all();
.groupBy(items.categoryId);
}
export function getGlobalTotals(db: Db = prodDb) {
return db
export async function getGlobalTotals(db: Db = prodDb) {
const [row] = await db
.select({
totalWeight: sql<number>`COALESCE(SUM(${items.weightGrams} * ${items.quantity}), 0)`,
totalCost: sql<number>`COALESCE(SUM(${items.priceCents} * ${items.quantity}), 0)`,
itemCount: sql<number>`COUNT(*)`,
})
.from(items)
.get();
.from(items);
return row;
}