Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop

This commit is contained in:
kittapath 2025-01-29 16:30:31 +07:00
commit 8eac85385c
5 changed files with 142 additions and 43 deletions

View file

@ -2593,9 +2593,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 ให้สร้างใหม่
@ -3123,19 +3130,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));
@ -3317,19 +3321,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));
@ -3547,19 +3548,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();
}
}

View file

@ -197,11 +197,17 @@ export class ProfileEmployee extends EntityBase {
isProbation: boolean;
@Column({
comment: "เกษียณ",
comment: "พ้นราชการ",
default: false,
})
isLeave: boolean;
@Column({
comment: "เกษียณ",
default: false,
})
isRetirement: boolean;
@Column({
comment: "สถานะการใช้งาน",
default: true,

View file

@ -334,6 +334,7 @@ export async function checkReturnCommandType(commandId: string) {
export async function checkExceptCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command);
const commandReciveRepository = AppDataSource.getRepository(CommandRecive)
const _type = await commandRepository.findOne({
where: {
id: commandId,
@ -341,9 +342,27 @@ export async function checkExceptCommandType(commandId: string) {
relations: ["commandType"],
});
if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) {
return false;
return { status: false, LeaveType: null, leaveRemark: null};
}
return true;
const _commandRecive = await commandReciveRepository.findOne({
where: { commandId: commandId }
});
let _leaveType: string =""
switch(String(_type?.commandType.code)){
case "C-PM-25" : {
_leaveType = "DISCIPLINE_SUSPEND"; //คำสั่งพักจากราชการ
break;
}
case "C-PM-26" : {
_leaveType = "DISCIPLINE_SUSPEND"; //คำสั่งให้ออกจากราชการไว้ก่อน
break;
}
default: {
_leaveType = ""
}
}
return { status: true, LeaveType: _leaveType, leaveRemark: _commandRecive ? _commandRecive.remarkVertical : null };
}
export async function checkCommandType(commandId: string) {

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileEmp1738139755428 implements MigrationInterface {
name = 'UpdateTableProfileEmp1738139755428'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`isRetirement\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`isRetirement\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileEmployee\` CHANGE \`isLeave\` \`isLeave\` tinyint NOT NULL COMMENT 'พ้นราชการ' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` CHANGE \`isLeave\` \`isLeave\` tinyint NOT NULL COMMENT 'พ้นราชการ' DEFAULT 0`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` CHANGE \`isLeave\` \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileEmployee\` CHANGE \`isLeave\` \`isLeave\` tinyint NOT NULL COMMENT 'เกษียณ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`isRetirement\``);
await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`isRetirement\``);
}
}