feat(F-160): completed feature

This commit is contained in:
chattie
2026-08-22 18:05:33 +02:00
parent f802a83773
commit 83a44980c6
12 changed files with 87 additions and 45 deletions

View File

@@ -375,7 +375,7 @@ export class ReportingService {
WHERE i.order_id IN (SELECT id FROM filtered_orders)
)
SELECT
${selectExpr}
${selectExpr},
COUNT(DISTINCT o.id)::int AS orders,
COUNT(DISTINCT o.user_id) FILTER (WHERE o.user_id IS NOT NULL)::int AS customers,
COALESCE(SUM(i.unit_price_cents * i.quantity), 0)::bigint AS gross_sales_cents,
@@ -576,7 +576,7 @@ export class ReportingService {
};
case 'terminal':
return {
groupExpr: 'terminal_id',
groupExpr: 'store_id, terminal_id',
selectExpr: "NULL::text AS period, NULL::text AS channel, o.store_id, o.terminal_id",
};
default:

View File

@@ -285,5 +285,27 @@ describe('ReportingService', () => {
expect(result.items).toHaveLength(1);
expect(result.items[0]!.storeId).toBe(storeId);
});
it('separates dimensional columns from aggregate metrics with a comma', async () => {
const pool = makeMockPool([]);
const svc = new ReportingService(pool);
await svc.sales(makeFilters({ groupBy: 'day' }));
expect(pool.query).toHaveBeenCalledWith(
expect.stringMatching(/NULL::uuid AS terminal_id,\s+COUNT\(DISTINCT o\.id\)/),
expect.any(Array),
);
});
it('groups terminal reports by both store and terminal', async () => {
const pool = makeMockPool([]);
const svc = new ReportingService(pool);
await svc.sales(makeFilters({ groupBy: 'terminal' }));
expect(pool.query).toHaveBeenCalledWith(
expect.stringContaining('GROUP BY store_id, terminal_id'),
expect.any(Array),
);
});
});
});