#2231
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s

This commit is contained in:
Adisak 2026-01-26 14:14:58 +07:00
parent 78778e0eb0
commit 6e6253887f

View file

@ -472,9 +472,9 @@ export class KeycloakController extends Controller {
@Post("user/admin")
async listUserKeycloak(
@Request() req: RequestWithUser,
@Body()
body:{
@Request() req: RequestWithUser,
@Body()
body: {
page: number,
pageSize: number,
keyword: string | null,
@ -507,9 +507,9 @@ export class KeycloakController extends Controller {
let typeCondition = "";
let checkChildConditions = "";
let conditions:any = {};
let conditions: any = {};
if(body.nodeId !== null && body.nodeId !== "" && body.nodeId !== undefined){
if (body.nodeId !== null && body.nodeId !== "" && body.nodeId !== undefined) {
if (body.node === 0) {
typeCondition = `current_holders.orgRootId = '${body.nodeId}'`;
if (!body.isAll) {
@ -533,9 +533,9 @@ export class KeycloakController extends Controller {
} else if (body.node === 4) {
typeCondition = `current_holders.orgChild4Id = '${body.nodeId}'`;
}
conditions = typeCondition;
if(checkChildConditions){
if (checkChildConditions) {
conditions += checkChildConditions;
}
}
@ -547,6 +547,11 @@ export class KeycloakController extends Controller {
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.roleKeycloaks", "roleKeycloaks")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.keycloak IS NOT NULL AND profile.keycloak != ''")
.andWhere(checkChildFromRole)
.andWhere(conditions)
@ -566,6 +571,13 @@ export class KeycloakController extends Controller {
}),
)
.orderBy("profile.citizenId", "ASC")
.orderBy("orgRoot.orgRootOrder", "ASC")
.addOrderBy("orgChild1.orgChild1Order", "ASC")
.addOrderBy("orgChild2.orgChild2Order", "ASC")
.addOrderBy("orgChild3.orgChild3Order", "ASC")
.addOrderBy("orgChild4.orgChild4Order", "ASC")
.addOrderBy("current_holders.posMasterOrder", "ASC")
.addOrderBy("current_holders.posMasterCreatedAt", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
@ -574,6 +586,11 @@ export class KeycloakController extends Controller {
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.roleKeycloaks", "roleKeycloaks")
.leftJoinAndSelect("profileEmployee.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''")
.andWhere(checkChildFromRole)
.andWhere(conditions)
@ -598,6 +615,13 @@ export class KeycloakController extends Controller {
}),
)
.orderBy("profileEmployee.citizenId", "ASC")
.orderBy("orgRoot.orgRootOrder", "ASC")
.addOrderBy("orgChild1.orgChild1Order", "ASC")
.addOrderBy("orgChild2.orgChild2Order", "ASC")
.addOrderBy("orgChild3.orgChild3Order", "ASC")
.addOrderBy("orgChild4.orgChild4Order", "ASC")
.addOrderBy("current_holders.posMasterOrder", "ASC")
.addOrderBy("current_holders.posMasterCreatedAt", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
@ -758,17 +782,17 @@ export class KeycloakController extends Controller {
}
@Get("user/role/{id}")
async getRoleUser(@Request() req: RequestWithUser,@Path("id") id: string) {
async getRoleUser(@Request() req: RequestWithUser, @Path("id") id: string) {
const profile = await this.profileRepo.findOne({
where: { keycloak: id },
relations: ["roleKeycloaks"],
});
if (
req.user.sub === id &&
req.user.role.some(x => x === 'ADMIN') &&
!req.user.role.some(x => x === 'SUPER_ADMIN')
!req.user.role.some(x => x === 'SUPER_ADMIN')
) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่มีสิทธิ์เข้าถึงข้อมูลนี้");
}