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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user