From 30fd8dd8410b198eb2a6078e9cfdb81228f4e5a5 Mon Sep 17 00:00:00 2001 From: Eli Morris-Heft Date: Sat, 12 Oct 2024 19:45:12 -0400 Subject: [PATCH] Add weekly signups in admin panel --- server/api/admin/stats.ts | 24 ++++++++++ src/components/pages/admin/AdminStatsPage.vue | 46 +++++++++++-------- src/lib/api/admin/stats.ts | 4 ++ 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/server/api/admin/stats.ts b/server/api/admin/stats.ts index 89115cd..0c28f68 100644 --- a/server/api/admin/stats.ts +++ b/server/api/admin/stats.ts @@ -86,3 +86,27 @@ GROUP BY "weekNumber" return res.status(200).send(success(activeUsersByWeek)); })); + +statsRouter.get('/weekly-signups', + requireAdminUser, + h(async (req: RequestWithUser, res: ApiResponse) => +{ + const results: { weekNumber: string; signups: number }[] = await dbClient.$queryRaw` +SELECT + EXTRACT(ISOYEAR FROM "createdAt") || '-' || lpad(EXTRACT(WEEK FROM "createdAt")::text, 2, '0') AS "weekNumber", + COUNT(DISTINCT "agentId") AS "signups" +FROM public."AuditEvent" +WHERE "eventType" = 'user:signup' +GROUP BY "weekNumber" +; + `; + + const now = new Date(); + const signupsByWeek = results.map(({ weekNumber, signups }) => { + const weekStart = format(parse(weekNumber, 'R-II', now), 'y-MM-dd'); + + return { weekStart, count: Number(signups) }; + }); + + return res.status(200).send(success(signupsByWeek)); +})); diff --git a/src/components/pages/admin/AdminStatsPage.vue b/src/components/pages/admin/AdminStatsPage.vue index dbf10e7..9cc8b46 100644 --- a/src/components/pages/admin/AdminStatsPage.vue +++ b/src/components/pages/admin/AdminStatsPage.vue @@ -1,7 +1,7 @@ @@ -48,13 +56,15 @@ onMounted(() => loadWeeklyActiveUsers()); :breadcrumbs="breadcrumbs" > -
+
-
- No stats found. Are you sure this thing is on? +
+
diff --git a/src/lib/api/admin/stats.ts b/src/lib/api/admin/stats.ts index a7857bf..631395c 100644 --- a/src/lib/api/admin/stats.ts +++ b/src/lib/api/admin/stats.ts @@ -9,3 +9,7 @@ const ENDPOINT = '/api/admin/stats'; export async function getWeeklyActiveUsers() { return callApiV1(ENDPOINT + '/weekly-active-users', 'GET'); } + +export async function getWeeklySignups() { + return callApiV1(ENDPOINT + '/weekly-signups', 'GET'); +}