fix: stats not take scope into account
This commit is contained in:
parent
91d741f363
commit
2cd92b2234
2 changed files with 33 additions and 5 deletions
|
|
@ -119,10 +119,24 @@ function mapImageLoc(id: string) {
|
||||||
export class BranchController extends Controller {
|
export class BranchController extends Controller {
|
||||||
@Get("stats")
|
@Get("stats")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async getStats() {
|
async getStats(@Request() req: RequestWithUser) {
|
||||||
const list = await prisma.branch.groupBy({
|
const list = await prisma.branch.groupBy({
|
||||||
_count: true,
|
_count: true,
|
||||||
by: "isHeadOffice",
|
by: "isHeadOffice",
|
||||||
|
where: {
|
||||||
|
AND: isSystem(req.user)
|
||||||
|
? undefined
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
user: { some: { userId: req.user.sub } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headOffice: globalAllow(req.user)
|
||||||
|
? { user: { some: { userId: req.user.sub } } }
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return list.reduce<Record<"hq" | "br", number>>(
|
return list.reduce<Record<"hq" | "br", number>>(
|
||||||
|
|
|
||||||
|
|
@ -177,14 +177,28 @@ function imageLocation(id: string) {
|
||||||
export class UserController extends Controller {
|
export class UserController extends Controller {
|
||||||
@Get("type-stats")
|
@Get("type-stats")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
async getUserTypeStats() {
|
async getUserTypeStats(@Request() req: RequestWithUser) {
|
||||||
const list = await prisma.user.groupBy({
|
const list = await prisma.user.groupBy({
|
||||||
by: "userType",
|
by: "userType",
|
||||||
_count: true,
|
_count: true,
|
||||||
where: {
|
where: {
|
||||||
AND: {
|
userRole: { not: "system" },
|
||||||
userRole: { not: "system" },
|
branch: isSystem(req.user)
|
||||||
},
|
? undefined
|
||||||
|
: {
|
||||||
|
some: {
|
||||||
|
branch: {
|
||||||
|
OR: [
|
||||||
|
{ user: { some: { userId: req.user.sub } } },
|
||||||
|
{
|
||||||
|
headOffice: !globalAllow(req.user)
|
||||||
|
? { user: { some: { userId: req.user.sub } } }
|
||||||
|
: undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue