From 1e06b3356fc5345b43f55be6ccd2bc6fa8f48715 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:51:46 +0700 Subject: [PATCH] feat: stats user by user type --- src/controllers/user-controller.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/controllers/user-controller.ts b/src/controllers/user-controller.ts index 6dd2c93..86e4afd 100644 --- a/src/controllers/user-controller.ts +++ b/src/controllers/user-controller.ts @@ -104,6 +104,27 @@ function imageLocation(id: string) { @Tags("User") @Security("keycloak") export class UserController extends Controller { + @Get("type-stats") + async getUserTypeStats() { + const list = await prisma.user.groupBy({ + by: "userType", + _count: true, + }); + + return list.reduce>( + (a, c) => { + a[c.userType] = c._count; + return a; + }, + { + USER: 0, + MESSENGER: 0, + DELEGATE: 0, + AGENCY: 0, + }, + ); + } + @Get() async getUser( @Query() userType?: UserType,