From e63510850b45ba85957c34ac8156055f62d3cf92 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 6 Sep 2024 11:56:15 +0700 Subject: [PATCH] feat: scope stats --- src/controllers/01-branch-controller.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/controllers/01-branch-controller.ts b/src/controllers/01-branch-controller.ts index dc94c0a..898cbce 100644 --- a/src/controllers/01-branch-controller.ts +++ b/src/controllers/01-branch-controller.ts @@ -106,7 +106,7 @@ type BranchUpdate = { export class BranchController extends Controller { @Get("stats") @Security("keycloak") - async getStats(@Request() req: RequestWithUser) { + async getStats(@Request() req: RequestWithUser, @Query() headOfficeId?: string) { const where = { AND: isSystem(req.user) ? undefined @@ -125,20 +125,21 @@ export class BranchController extends Controller { const [hq, br, virtual] = await prisma.$transaction([ prisma.branch.count({ where: { + id: headOfficeId ? headOfficeId : undefined, headOfficeId: null, ...where, }, }), prisma.branch.count({ where: { - headOfficeId: { not: null }, + headOfficeId: headOfficeId ? headOfficeId : { not: null }, virtual: false, ...where, }, }), prisma.branch.count({ where: { - headOfficeId: { not: null }, + headOfficeId: headOfficeId ? headOfficeId : { not: null }, virtual: true, ...where, },