fix condition command 08,09

This commit is contained in:
Bright 2024-12-02 18:14:07 +07:00
parent d0d7c2d418
commit 24427ef311

View file

@ -2215,7 +2215,6 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name; profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date(); profile.lastUpdatedAt = new Date();
// profile.dateStart = new Date();
if (item.isLeave == true) { if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
@ -2236,21 +2235,25 @@ export class CommandController extends Controller {
const returnWork = await checkReturnCommandType(String(item.commandId)); const returnWork = await checkReturnCommandType(String(item.commandId));
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user //คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) { if (returnWork && item.isGovernment) {
/*if (profile.keycloak != null) { let userKeycloakId;
const enableActive = await enableStatus(profile.keycloak, true); userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
} else {*/
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
}); });
// if (typeof userKeycloakId !== "string") { // กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่
// throw new Error(userKeycloakId.errorMessage); if (profile.keycloak != null && userKeycloakId && userKeycloakId.error === "User exists with same username") {
// } const delUserKeycloak = await deleteUser(profile.keycloak);
if(delUserKeycloak) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
}
}
const list = await getRoles(); const list = await getRoles();
if (!Array.isArray(list)) let result = false;
throw new Error("Failed. Cannot get role(s) data from the server."); if (Array.isArray(list) && userKeycloakId) {
const result = await addUserRoles( result = await addUserRoles(
userKeycloakId, userKeycloakId,
list list
.filter((v) => v.name === "USER") .filter((v) => v.name === "USER")
@ -2259,10 +2262,9 @@ export class CommandController extends Controller {
name: x.name, name: x.name,
})), })),
); );
// if (!result) throw new Error("Failed. Cannot set user's role."); }
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
/*}*/
profile.isActive = true; profile.isActive = true;
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
} }
await this.profileRepository.save(profile); await this.profileRepository.save(profile);