feat: scope stats
This commit is contained in:
parent
dec2722670
commit
e63510850b
1 changed files with 4 additions and 3 deletions
|
|
@ -106,7 +106,7 @@ type BranchUpdate = {
|
||||||
export class BranchController extends Controller {
|
export class BranchController extends Controller {
|
||||||
@Get("stats")
|
@Get("stats")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async getStats(@Request() req: RequestWithUser) {
|
async getStats(@Request() req: RequestWithUser, @Query() headOfficeId?: string) {
|
||||||
const where = {
|
const where = {
|
||||||
AND: isSystem(req.user)
|
AND: isSystem(req.user)
|
||||||
? undefined
|
? undefined
|
||||||
|
|
@ -125,20 +125,21 @@ export class BranchController extends Controller {
|
||||||
const [hq, br, virtual] = await prisma.$transaction([
|
const [hq, br, virtual] = await prisma.$transaction([
|
||||||
prisma.branch.count({
|
prisma.branch.count({
|
||||||
where: {
|
where: {
|
||||||
|
id: headOfficeId ? headOfficeId : undefined,
|
||||||
headOfficeId: null,
|
headOfficeId: null,
|
||||||
...where,
|
...where,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.branch.count({
|
prisma.branch.count({
|
||||||
where: {
|
where: {
|
||||||
headOfficeId: { not: null },
|
headOfficeId: headOfficeId ? headOfficeId : { not: null },
|
||||||
virtual: false,
|
virtual: false,
|
||||||
...where,
|
...where,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.branch.count({
|
prisma.branch.count({
|
||||||
where: {
|
where: {
|
||||||
headOfficeId: { not: null },
|
headOfficeId: headOfficeId ? headOfficeId : { not: null },
|
||||||
virtual: true,
|
virtual: true,
|
||||||
...where,
|
...where,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue