feat: scope stats

This commit is contained in:
Methapon Metanipat 2024-09-06 11:56:15 +07:00
parent dec2722670
commit e63510850b

View file

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