From 7cfc49eae045541dcac8598c2646fd95c2cd35b4 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:09:49 +0700 Subject: [PATCH] feat: count customer by type --- src/controllers/customer-controller.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index e71485c..cb18ca5 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -52,6 +52,25 @@ function imageLocation(id: string) { @Tags("Customer") @Security("keycloak") export class CustomerController extends Controller { + @Get("type-stats") + async stat() { + const list = await prisma.customer.groupBy({ + by: "customerType", + _count: true, + }); + + return list.reduce>( + (a, c) => { + a[c.customerType] = c._count; + return a; + }, + { + CORP: 0, + PERS: 0, + }, + ); + } + @Get() async list( @Query() query: string = "",