feat: count customer by type

This commit is contained in:
Methapon2001 2024-06-07 09:09:49 +07:00
parent 818dd044b6
commit 7cfc49eae0

View file

@ -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<Record<CustomerType, number>>(
(a, c) => {
a[c.customerType] = c._count;
return a;
},
{
CORP: 0,
PERS: 0,
},
);
}
@Get()
async list(
@Query() query: string = "",