From efa02cd1df8af29df1c4f0e4d34536ece116a80f Mon Sep 17 00:00:00 2001 From: Andrei Date: Wed, 8 Oct 2025 11:02:49 +0000 Subject: [PATCH] fix: Correct database table and column names in analytics queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed 'devices' to 'device_registry' in getDeviceDistribution - Changed 'date_of_birth' to 'birth_date' in getAgeDistribution - Added deleted_at filter to exclude deleted children - Added proper ordering to age distribution results 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../admin/dashboard/dashboard.service.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/maternal-app/maternal-app-backend/src/modules/admin/dashboard/dashboard.service.ts b/maternal-app/maternal-app-backend/src/modules/admin/dashboard/dashboard.service.ts index 1a0f933..c0620ff 100644 --- a/maternal-app/maternal-app-backend/src/modules/admin/dashboard/dashboard.service.ts +++ b/maternal-app/maternal-app-backend/src/modules/admin/dashboard/dashboard.service.ts @@ -111,7 +111,7 @@ export class DashboardService { ELSE 'Web' END as name, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER () as value - FROM devices + FROM device_registry GROUP BY platform`, ); @@ -163,12 +163,21 @@ export class DashboardService { END as age, COUNT(*) as count FROM ( - SELECT EXTRACT(YEAR FROM AGE(date_of_birth)) * 12 + EXTRACT(MONTH FROM AGE(date_of_birth)) as age_months + SELECT EXTRACT(YEAR FROM AGE(birth_date)) * 12 + EXTRACT(MONTH FROM AGE(birth_date)) as age_months FROM children - WHERE date_of_birth IS NOT NULL + WHERE birth_date IS NOT NULL AND deleted_at IS NULL ) ages GROUP BY age - ORDER BY age`, + ORDER BY + CASE age + WHEN '0-6 months' THEN 1 + WHEN '6-12 months' THEN 2 + WHEN '1-2 years' THEN 3 + WHEN '2-3 years' THEN 4 + WHEN '3-4 years' THEN 5 + WHEN '4-5 years' THEN 6 + ELSE 7 + END`, ); return result.map((row: any) => ({