diff --git a/src/controllers/branch/branch-controller.ts b/src/controllers/branch/branch-controller.ts index 1bdd334..cb9b096 100644 --- a/src/controllers/branch/branch-controller.ts +++ b/src/controllers/branch/branch-controller.ts @@ -61,6 +61,27 @@ type BranchUpdate = { @Tags("Branch") @Security("keycloak") export class BranchController extends Controller { + @Get("stats") + async getStat() { + const list = await prisma.branchUser.groupBy({ + by: ["branchId"], + _count: true, + }); + + const record = await prisma.branch.findMany({ + select: { + id: true, + nameEN: true, + nameTH: true, + }, + }); + + return record.map((a) => ({ + ...a, + userCount: list.find((b) => b.branchId === a.id)?._count ?? 0, + })); + } + @Get() async getBranch( @Query() zipCode?: string,