feat: add user stat for each branch

This commit is contained in:
Methapon2001 2024-04-03 17:33:19 +07:00
parent 91e2f83529
commit ad4861b04c

View file

@ -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,