feat: add user stat for each branch
This commit is contained in:
parent
91e2f83529
commit
ad4861b04c
1 changed files with 21 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue