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";
|
||||
import { filterStatus } from "../services/prisma";
|
||||
import {
|
||||
branchActiveOnlyCond,
|
||||
branchRelationPermInclude,
|
||||
createPermCheck,
|
||||
createPermCondition,
|
||||
|
|
@ -263,6 +264,7 @@ export class UserController extends Controller {
|
|||
@Query() pageSize: number = 30,
|
||||
@Query() status?: Status,
|
||||
@Query() responsibleDistrictId?: string,
|
||||
@Query() activeBranchOnly?: boolean,
|
||||
) {
|
||||
return this.getUserByCriteria(
|
||||
req,
|
||||
|
|
@ -273,6 +275,7 @@ export class UserController extends Controller {
|
|||
pageSize,
|
||||
status,
|
||||
responsibleDistrictId,
|
||||
activeBranchOnly,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -287,6 +290,7 @@ export class UserController extends Controller {
|
|||
@Query() pageSize: number = 30,
|
||||
@Query() status?: Status,
|
||||
@Query() responsibleDistrictId?: string,
|
||||
@Query() activeBranchOnly?: boolean,
|
||||
@Body()
|
||||
body?: {
|
||||
userId?: string[];
|
||||
|
|
@ -337,11 +341,13 @@ export class UserController extends Controller {
|
|||
userType,
|
||||
...filterStatus(status),
|
||||
branch: isSystem(req.user)
|
||||
? undefined
|
||||
? activeBranchOnly
|
||||
? { some: { branch: branchActiveOnlyCond(activeBranchOnly) } }
|
||||
: undefined
|
||||
: {
|
||||
some: {
|
||||
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(
|
||||
globalAllow: (user: RequestWithUser["user"]) => boolean,
|
||||
): (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue