From 671c9fc791077567f89612b3fad6d4319a46ec0e Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Fri, 20 Oct 2023 14:28:51 -0500 Subject: [PATCH 1/2] Fix usage. --- src/pages/api/users/[id]/usage.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/api/users/[id]/usage.ts b/src/pages/api/users/[id]/usage.ts index 7cb40d61..93dd0553 100644 --- a/src/pages/api/users/[id]/usage.ts +++ b/src/pages/api/users/[id]/usage.ts @@ -66,8 +66,8 @@ export default async ( const usage = websiteUsage.reduce( (acc, cv) => { - acc.websiteEventUsage += cv.websiteEventUsage; - acc.eventDataUsage += cv.eventDataUsage; + acc.websiteEventUsage += Number(cv.websiteEventUsage); + acc.eventDataUsage += Number(cv.eventDataUsage); return acc; }, From 4153db48d20512ef9fb75025a6d3dacab61b446d Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Fri, 20 Oct 2023 14:34:02 -0500 Subject: [PATCH 2/2] Better fix, usage. --- src/pages/api/users/[id]/usage.ts | 4 ++-- src/queries/analytics/eventData/getEventDataUsage.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pages/api/users/[id]/usage.ts b/src/pages/api/users/[id]/usage.ts index 93dd0553..7cb40d61 100644 --- a/src/pages/api/users/[id]/usage.ts +++ b/src/pages/api/users/[id]/usage.ts @@ -66,8 +66,8 @@ export default async ( const usage = websiteUsage.reduce( (acc, cv) => { - acc.websiteEventUsage += Number(cv.websiteEventUsage); - acc.eventDataUsage += Number(cv.eventDataUsage); + acc.websiteEventUsage += cv.websiteEventUsage; + acc.eventDataUsage += cv.eventDataUsage; return acc; }, diff --git a/src/queries/analytics/eventData/getEventDataUsage.ts b/src/queries/analytics/eventData/getEventDataUsage.ts index 78bf7c91..7866a600 100644 --- a/src/queries/analytics/eventData/getEventDataUsage.ts +++ b/src/queries/analytics/eventData/getEventDataUsage.ts @@ -8,7 +8,11 @@ export function getEventDataUsage(...args: [websiteIds: string[], startDate: Dat }); } -function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) { +function clickhouseQuery( + websiteIds: string[], + startDate: Date, + endDate: Date, +): Promise<{ websiteId: string; count: number }[]> { const { rawQuery } = clickhouse; return rawQuery( @@ -26,5 +30,9 @@ function clickhouseQuery(websiteIds: string[], startDate: Date, endDate: Date) { startDate, endDate, }, - ); + ).then(a => { + return Object.values(a).map(a => { + return { websiteId: a.websiteId, count: Number(a.count) }; + }); + }); }