diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 8bf28811..0ec76d94 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -60,7 +60,7 @@ import { ProfileFamilyFather } from "../entities/ProfileFamilyFather"; import Extension from "../interfaces/extension"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; -import { updateName } from "../keycloak"; +import { updateName, deleteUser } from "../keycloak"; import permission from "../interfaces/permission"; import { PosMasterAct } from "../entities/PosMasterAct"; import axios from "axios"; @@ -9405,6 +9405,7 @@ export class ProfileController extends Controller { }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const before = structuredClone(profile); + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; @@ -9412,6 +9413,17 @@ export class ProfileController extends Controller { await removeProfileInOrganize(profile.id, "OFFICER"); } profile.leaveType = "RETIRE_DECEASED"; + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } await this.profileRepo.save(profile, { data: request }); setLogDataDiff(request, { before, after: profile }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index c54ad861..d2f5cf71 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -68,6 +68,7 @@ import permission from "../interfaces/permission"; import axios from "axios"; import { Position } from "../entities/Position"; import { EmployeePosition } from "../entities/EmployeePosition"; +import { deleteUser } from "../keycloak"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -4113,13 +4114,24 @@ export class ProfileEmployeeController extends Controller { where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } profile.leaveType = "RETIRE_DECEASED"; await this.profileRepo.save(profile); diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 6d98310d..3fc25988 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -66,6 +66,7 @@ import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; import permission from "../interfaces/permission"; import axios from "axios"; +import { deleteUser } from "../keycloak"; @Route("api/v1/org/profile-temp") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -3201,13 +3202,25 @@ export class ProfileEmployeeTempController extends Controller { where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + let _null:any = null; profile.isLeave = requestBody.isLeave; profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + profile.leaveType = "RETIRE_DECEASED"; + profile.position = _null; + profile.posLevelId = _null; + profile.posTypeId = _null; + if (profile.keycloak != null) { + const delUserKeycloak = await deleteUser(profile.keycloak); + if (delUserKeycloak) { + profile.keycloak = _null; + profile.roleKeycloaks = []; + profile.isActive = false; + } + } await this.profileRepo.save(profile); return new HttpSuccess();