feat: stats user by user type

This commit is contained in:
Methapon2001 2024-04-09 17:51:46 +07:00
parent 1f96418de0
commit 1e06b3356f

View file

@ -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<Record<UserType, number>>(
(a, c) => {
a[c.userType] = c._count;
return a;
},
{
USER: 0,
MESSENGER: 0,
DELEGATE: 0,
AGENCY: 0,
},
);
}
@Get()
async getUser(
@Query() userType?: UserType,