From 059f473a3857d64f3b2b898e174ab6be226bdd31 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 13 Nov 2024 01:51:33 +0100 Subject: [PATCH] fix(analyticsApi): fixed last_30_days_data (3) --- analyticsApi/main.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/analyticsApi/main.go b/analyticsApi/main.go index ddbf6e4..048c4f8 100644 --- a/analyticsApi/main.go +++ b/analyticsApi/main.go @@ -138,15 +138,20 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { ( SELECT json_group_array( json_object( - 'date', strftime('%Y-%m-%d', created), - 'count', COUNT(id) + 'date', date, + 'count', daily_count ) ) - FROM analyticsPageViews - WHERE - path = view.path AND - created >= datetime('now', '-30 days') - GROUP BY strftime('%Y-%m-%d', created) + FROM ( + SELECT + strftime('%Y-%m-%d', created) AS date, + COUNT(id) AS daily_count + FROM analyticsPageViews + WHERE + path = view.path AND + created >= datetime('now', '-30 days') + GROUP BY date + ) AS daily_data ) AS last_30_days_data FROM analyticsPageViews view