feat: accept param active branch only
This commit is contained in:
parent
cb9c9cef68
commit
9630d02924
2 changed files with 19 additions and 2 deletions
|
|
@ -40,6 +40,7 @@ import {
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
import {
|
import {
|
||||||
|
branchActiveOnlyCond,
|
||||||
branchRelationPermInclude,
|
branchRelationPermInclude,
|
||||||
createPermCheck,
|
createPermCheck,
|
||||||
createPermCondition,
|
createPermCondition,
|
||||||
|
|
@ -263,6 +264,7 @@ export class UserController extends Controller {
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() responsibleDistrictId?: string,
|
@Query() responsibleDistrictId?: string,
|
||||||
|
@Query() activeBranchOnly?: boolean,
|
||||||
) {
|
) {
|
||||||
return this.getUserByCriteria(
|
return this.getUserByCriteria(
|
||||||
req,
|
req,
|
||||||
|
|
@ -273,6 +275,7 @@ export class UserController extends Controller {
|
||||||
pageSize,
|
pageSize,
|
||||||
status,
|
status,
|
||||||
responsibleDistrictId,
|
responsibleDistrictId,
|
||||||
|
activeBranchOnly,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -287,6 +290,7 @@ export class UserController extends Controller {
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() responsibleDistrictId?: string,
|
@Query() responsibleDistrictId?: string,
|
||||||
|
@Query() activeBranchOnly?: boolean,
|
||||||
@Body()
|
@Body()
|
||||||
body?: {
|
body?: {
|
||||||
userId?: string[];
|
userId?: string[];
|
||||||
|
|
@ -337,11 +341,13 @@ export class UserController extends Controller {
|
||||||
userType,
|
userType,
|
||||||
...filterStatus(status),
|
...filterStatus(status),
|
||||||
branch: isSystem(req.user)
|
branch: isSystem(req.user)
|
||||||
? undefined
|
? activeBranchOnly
|
||||||
|
? { some: { branch: branchActiveOnlyCond(activeBranchOnly) } }
|
||||||
|
: undefined
|
||||||
: {
|
: {
|
||||||
some: {
|
some: {
|
||||||
branch: {
|
branch: {
|
||||||
OR: permissionCond(req.user),
|
OR: permissionCond(req.user, { activeOnly: activeBranchOnly }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,17 @@ export function branchRelationPermInclude(user: RequestWithUser["user"]) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function branchActiveOnlyCond(activeOnly?: boolean) {
|
||||||
|
return activeOnly
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ headOffice: { status: { not: Status.INACTIVE } } },
|
||||||
|
{ headOffice: null, status: { not: Status.INACTIVE } },
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function createPermCondition(
|
export function createPermCondition(
|
||||||
globalAllow: (user: RequestWithUser["user"]) => boolean,
|
globalAllow: (user: RequestWithUser["user"]) => boolean,
|
||||||
): (
|
): (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue