Merge branch 'develop' into adiDev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s

This commit is contained in:
adisak 2026-04-02 12:04:55 +07:00
commit 34e8ec8434
5 changed files with 81 additions and 35 deletions

View file

@ -1657,7 +1657,8 @@ export class CommandController extends Controller {
// console.log("4. disable keycloak/authen")
const delUserKeycloak = await deleteUser(_profile.keycloak, adminToken);
if (delUserKeycloak) {
_profile.keycloak = "";
// Task #228
// _profile.keycloak = "";
_profile.roleKeycloaks = [];
}
}
@ -1713,7 +1714,8 @@ export class CommandController extends Controller {
// disable keycloak/authen
const delUserKeycloak = await deleteUser(_profileEmp.keycloak, adminToken);
if (delUserKeycloak) {
_profileEmp.keycloak = "";
// Task #228
// _profileEmp.keycloak = "";
_profileEmp.roleKeycloaks = [];
}
}
@ -4131,7 +4133,8 @@ export class CommandController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -4535,7 +4538,8 @@ export class CommandController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -4755,7 +4759,8 @@ export class CommandController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -5251,7 +5256,8 @@ export class CommandController extends Controller {
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
// Task #228
// _profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
}
@ -5434,7 +5440,8 @@ export class CommandController extends Controller {
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
// Task #228
// _profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
}
@ -5772,7 +5779,8 @@ export class CommandController extends Controller {
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
// Task #228
// _profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
}
@ -6209,7 +6217,8 @@ export class CommandController extends Controller {
if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
// Task #228
// _profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
}
@ -6506,7 +6515,8 @@ export class CommandController extends Controller {
if (profileEmployee.keycloak != null) {
// const delUserKeycloak = await deleteUser(profileEmployee.keycloak);
// if (delUserKeycloak) {
profileEmployee.keycloak = _null;
// Task #228
// profileEmployee.keycloak = _null;
profileEmployee.roleKeycloaks = [];
profileEmployee.isActive = false;
// }
@ -6837,12 +6847,36 @@ export class CommandController extends Controller {
}
//Position
if (item.bodyPosition && item.bodyPosition != null) {
const posMaster = await this.posMasterRepository.findOne({
where: { id: item.bodyPosition.posmasterId },
// STEP 1: หา posMaster ที่จะใช้งานตาม id ที่ส่งมา (อาจเป็นตำแหน่งเก่าหรือใหม่ก็ได้)
let posMaster = await this.posMasterRepository.findOne({
where: {
id: item.bodyPosition.posmasterId,
},
relations: { orgRevision: true }
});
// เช็คว่า posMaster ที่หามาอยู่ในโครงสร้างปัจจุบันหรือไม่
const isCurrent = posMaster?.orgRevision?.orgRevisionIsCurrent === true &&
posMaster?.orgRevision?.orgRevisionIsDraft === false;
// ถ้าไม่อยู่ในโครงสร้างปัจจุบัน ให้หาตัวใหม่จาก ancestorDNA
if (!isCurrent && posMaster?.ancestorDNA) {
posMaster = await this.posMasterRepository.findOne({
where: {
ancestorDNA: posMaster.ancestorDNA,
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
},
relations: { orgRevision: true }
});
}
if (posMaster == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
// STEP 2: เคลียร์ข้อมูลตำแหน่งเก่าที่ครองอยู่ ในโครงสร้างปัจจุบัน
const posMasterOld = await this.posMasterRepository.findOne({
where: {
current_holderId: profile.id,
@ -6850,10 +6884,12 @@ export class CommandController extends Controller {
},
});
if (posMasterOld != null) {
// เคลียร์คนครองเก่าออกจากตำแหน่งเดิม
posMasterOld.current_holderId = null;
posMasterOld.lastUpdatedAt = new Date();
}
// หา position เก่าที่เลือกไว้ แล้วเคลียร์การเลือก
const positionOld = await this.positionRepository.findOne({
where: {
posMasterId: posMasterOld?.id,
@ -6865,9 +6901,10 @@ export class CommandController extends Controller {
await this.positionRepository.save(positionOld);
}
// STEP 3: เคลียร์ position ที่เลือกไว้อื่นๆ ใน posMaster ตัวใหม่
const checkPosition = await this.positionRepository.find({
where: {
posMasterId: item.bodyPosition.posmasterId,
posMasterId: posMaster.id,
positionIsSelected: true,
},
});
@ -6879,6 +6916,7 @@ export class CommandController extends Controller {
await this.positionRepository.save(clearPosition);
}
// STEP 4: กำหนดคนครองใหม่ให้กับ posMaster
posMaster.current_holderId = profile.id;
posMaster.lastUpdatedAt = new Date();
// posMaster.conditionReason = _null;
@ -6889,10 +6927,11 @@ export class CommandController extends Controller {
}
await this.posMasterRepository.save(posMaster);
// STEP 5: กำหนด position ใหม่
const positionNew = await this.positionRepository.findOne({
where: {
id: item.bodyPosition.positionId,
posMasterId: item.bodyPosition.posmasterId,
posMasterId: posMaster.id, // ใช้ id ของ posMaster ตัวใหม่
},
});
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ

View file

@ -11133,9 +11133,9 @@ export class ProfileController extends Controller {
}
/**
* API
* API
*
* @summary (ADMIN)
* @summary (ADMIN)
*
* @param {string} id Id
*/
@ -11263,7 +11263,8 @@ export class ProfileController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -11371,7 +11372,7 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.keycloak IS NULL")
.where("profile.isActive = :isActive", { isActive: false })
.andWhere(
new Brackets((qb) => {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });

View file

@ -5560,9 +5560,9 @@ export class ProfileEmployeeController extends Controller {
}
/**
* API
* API
*
* @summary (ADMIN)
* @summary (ADMIN)
*
* @param {string} id Id
*/
@ -5687,7 +5687,8 @@ export class ProfileEmployeeController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -6161,7 +6162,7 @@ export class ProfileEmployeeController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.keycloak IS NULL")
.where("profile.isActive = :isActive", { isActive: false })
.andWhere(
new Brackets((qb) => {
qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` });

View file

@ -3459,9 +3459,9 @@ export class ProfileEmployeeTempController extends Controller {
}
/**
* API
* API
*
* @summary (ADMIN)
* @summary (ADMIN)
*
* @param {string} id Id
*/
@ -3586,7 +3586,8 @@ export class ProfileEmployeeTempController extends Controller {
if (profile.keycloak != null) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if (delUserKeycloak) {
profile.keycloak = _null;
// Task #228
// profile.keycloak = _null;
profile.roleKeycloaks = [];
profile.isActive = false;
}
@ -3987,7 +3988,7 @@ export class ProfileEmployeeTempController extends Controller {
case "citizenId":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
isActive: false,
citizenId: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
@ -3999,7 +4000,7 @@ export class ProfileEmployeeTempController extends Controller {
case "firstname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
isActive: false,
firstName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
@ -4011,7 +4012,7 @@ export class ProfileEmployeeTempController extends Controller {
case "lastname":
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
isActive: false,
lastName: Like(`%${body.keyword}%`),
},
relations: ["posType", "posLevel", "current_holders"],
@ -4023,7 +4024,7 @@ export class ProfileEmployeeTempController extends Controller {
default:
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
keycloak: IsNull(),
isActive: false,
},
relations: ["posType", "posLevel", "current_holders"],
skip,

View file

@ -274,14 +274,16 @@ export class KeycloakController extends Controller {
});
if (!profileEmp) {
} else {
const _null: any = null;
profileEmp.keycloak = _null;
// Task #228
// const _null: any = null;
// profileEmp.keycloak = _null;
profileEmp.roleKeycloaks = [];
await this.profileEmpRepo.save(profileEmp);
}
} else {
const _null: any = null;
profile.keycloak = _null;
// Task #228
// const _null: any = null;
// profile.keycloak = _null;
profile.roleKeycloaks = [];
await this.profileRepo.save(profile);
return new HttpSuccess();
@ -566,7 +568,8 @@ export class KeycloakController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profile.keycloak IS NOT NULL AND profile.keycloak != ''")
// .where("profile.keycloak IS NOT NULL AND profile.keycloak != ''")
.where("profile.isActive = :isActive", { isActive: true })
.andWhere(checkChildFromRole)
.andWhere(conditions)
.andWhere(
@ -609,7 +612,8 @@ export class KeycloakController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''")
// .where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''")
.where("profileEmployee.isActive = :isActive", { isActive: true })
.andWhere(checkChildFromRole)
.andWhere(conditions)
.andWhere({ employeeClass: "PERM" })