migrate + fix issue #993

This commit is contained in:
Bright 2025-01-29 15:41:14 +07:00
parent 7a0ab2271d
commit 4011abe5ea
5 changed files with 142 additions and 43 deletions

View file

@ -2579,9 +2579,16 @@ export class CommandController extends Controller {
profile.posTypeId = _null;
profile.posLevelId = _null;
}
const returnWork = await checkReturnCommandType(String(item.commandId));
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) {
if (item.isGovernment == true) {
const returnWork = await checkReturnCommandType(String(item.commandId));
if (returnWork) {
profile.leaveReason = _null;
profile.leaveCommandId = _null;
profile.leaveCommandNo = _null;
profile.leaveRemark = _null;
profile.leaveDate = _null;
profile.leaveType = _null;
}
let userKeycloakId;
const checkUser = await getUserByUsername(profile.citizenId);
//ถ้ายังไม่มี user keycloak ให้สร้างใหม่
@ -3109,19 +3116,16 @@ export class CommandController extends Controller {
_profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "OFFICER");
// }
// //คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
// else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
// // const enableActive = await enableStatus(_profile.keycloak, false);
// // if (!enableActive) throw new Error("Failed. Cannot change enable status.");
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status){
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.date ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
}
}
const clearProfile = await checkCommandType(String(item.commandId));
@ -3303,19 +3307,16 @@ export class CommandController extends Controller {
_profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
// }
// //คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
// else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
// // const enableActive = await enableStatus(_profile.keycloak, false);
// // if (!enableActive) throw new Error("Failed. Cannot change enable status.");
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.date ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
}
}
const clearProfile = await checkCommandType(String(item.commandId));
@ -3533,19 +3534,16 @@ export class CommandController extends Controller {
_profile.lastUpdateUserId = req.user.sub;
_profile.lastUpdateFullName = req.user.name;
_profile.lastUpdatedAt = new Date();
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
// }
// //คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
// else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
// // const enableActive = await enableStatus(_profile.keycloak, false);
// // if (!enableActive) throw new Error("Failed. Cannot change enable status.");
const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) {
_profile.keycloak = _null;
_profile.roleKeycloaks = [];
_profile.isActive = false;
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
_profile.leaveRemark = exceptClear.leaveRemark ?? _null;
_profile.leaveDate = item.date ?? _null;
_profile.leaveType = exceptClear.LeaveType ?? _null;
}
}
const clearProfile = await checkCommandType(String(item.commandId));

View file

@ -1,4 +1,4 @@
import { Controller, Get, Post, Route, Tags, Body, Path, Response } from "tsoa";
import { Controller, Get, Post, Route, Tags, Body, Path, Response, Patch } from "tsoa";
import { OrgRevision } from "../entities/OrgRevision";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
@ -1159,4 +1159,60 @@ export class OrganizationUnauthorizeController extends Controller {
await this.profileRepo.save(profile);
return new HttpSuccess("Email verified successfully.");
}
@Patch("retirement")
public async updateStatusRetirement(
@Body()
body: {
data: {
profileId: string;
}[];
},
) {
let profiles: Profile[] = [];
let _null: any = null;
await Promise.all(
body.data.map(async (item) => {
const _profile = await this.profileRepo.findOneBy({ id: item.profileId });
if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
_profile.isRetirement = true;
_profile.isLeave = true;
_profile.leaveType = "RETIRE";
_profile.leaveDate = new Date();
_profile.dateLeave = new Date();
_profile.lastUpdatedAt = new Date();
profiles.push(_profile);
})
);
await this.profileRepo.save(profiles);
return new HttpSuccess();
}
@Patch("retirement-employee")
public async updateStatusRetirementEmp(
@Body()
body: {
data: {
profileId: string;
}[];
},
) {
let profiles: ProfileEmployee[] = [];
let _null: any = null;
await Promise.all(
body.data.map(async (item) => {
const _profile = await this.profileEmpRepo.findOneBy({ id: item.profileId });
if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
_profile.isRetirement = true;
_profile.isLeave = true;
_profile.leaveType = "RETIRE";
_profile.leaveDate = new Date();
_profile.dateLeave = new Date();
_profile.lastUpdatedAt = new Date();
profiles.push(_profile);
})
);
await this.profileEmpRepo.save(profiles);
return new HttpSuccess();
}
}