From b2c8bdecf35017543706c52f2ef8d2aa2c9ff496 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 27 Jan 2025 17:50:21 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B9=80=E0=B8=AB=E0=B8=95?= =?UTF-8?q?=E0=B8=B8=E0=B8=9C=E0=B8=A5=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9E?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=88=E0=B8=B2=E0=B8=81=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=8A=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=83=E0=B8=99=E0=B8=97?= =?UTF-8?q?=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=20#1240?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 49 +++++++++++++++++--- src/controllers/ProfileController.ts | 1 + src/controllers/ProfileEmployeeController.ts | 1 + src/interfaces/utils.ts | 49 ++++++++++++++++++-- 4 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 1a562906..7cc6c4b4 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2561,7 +2561,7 @@ export class CommandController extends Controller { await removeProfileInOrganize(profile.id, "OFFICER"); } const clearProfile = await checkCommandType(String(item.commandId)); - if (clearProfile) { + if (clearProfile.status) { if (profile.keycloak != null) { const delUserKeycloak = await deleteUser(profile.keycloak); if (delUserKeycloak) { @@ -2570,6 +2570,11 @@ export class CommandController extends Controller { profile.isActive = false; } } + profile.leaveCommandId = item.commandId ?? _null; + profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveRemark = clearProfile.leaveRemark ?? _null; + profile.leaveDate = item.date ?? _null; + profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; profile.posLevelId = _null; @@ -2715,7 +2720,7 @@ export class CommandController extends Controller { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } const clearProfile = await checkCommandType(String(item.commandId)); - if (clearProfile) { + if (clearProfile.status) { if (profile.keycloak != null) { const delUserKeycloak = await deleteUser(profile.keycloak); if (delUserKeycloak) { @@ -2724,6 +2729,11 @@ export class CommandController extends Controller { profile.isActive = false; } } + profile.leaveCommandId = item.commandId ?? _null; + profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveRemark = clearProfile.leaveRemark ?? _null; + profile.leaveDate = item.date ?? _null; + profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; profile.posLevelId = _null; @@ -2803,7 +2813,7 @@ export class CommandController extends Controller { } const clearProfile = await checkCommandType(String(item.commandId)); const _null: any = null; - if (clearProfile) { + if (clearProfile.status) { if (profile.keycloak != null) { const delUserKeycloak = await deleteUser(profile.keycloak); if (delUserKeycloak) { @@ -2812,6 +2822,11 @@ export class CommandController extends Controller { profile.isActive = false; } } + profile.leaveCommandId = item.commandId ?? _null; + profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveRemark = clearProfile.leaveRemark ?? _null; + profile.leaveDate = item.date ?? _null; + profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; profile.posLevelId = _null; @@ -3110,7 +3125,7 @@ export class CommandController extends Controller { } } const clearProfile = await checkCommandType(String(item.commandId)); - if (clearProfile) { + if (clearProfile.status) { if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -3119,6 +3134,11 @@ export class CommandController extends Controller { _profile.isActive = false; } } + _profile.leaveCommandId = item.commandId ?? _null; + _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveRemark = clearProfile.leaveRemark ?? _null; + _profile.leaveDate = item.date ?? _null; + _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; _profile.posLevelId = _null; @@ -3299,7 +3319,7 @@ export class CommandController extends Controller { } } const clearProfile = await checkCommandType(String(item.commandId)); - if (clearProfile) { + if (clearProfile.status) { if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -3308,6 +3328,11 @@ export class CommandController extends Controller { _profile.isActive = false; } } + _profile.leaveCommandId = item.commandId ?? _null; + _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveRemark = clearProfile.leaveRemark ?? _null; + _profile.leaveDate = item.date ?? _null; + _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; _profile.posLevelId = _null; @@ -3524,7 +3549,7 @@ export class CommandController extends Controller { } } const clearProfile = await checkCommandType(String(item.commandId)); - if (clearProfile) { + if (clearProfile.status) { if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -3533,6 +3558,11 @@ export class CommandController extends Controller { _profile.isActive = false; } } + _profile.leaveCommandId = item.commandId ?? _null; + _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveRemark = clearProfile.leaveRemark ?? _null; + _profile.leaveDate = item.date ?? _null; + _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; _profile.posLevelId = _null; @@ -3851,7 +3881,7 @@ export class CommandController extends Controller { await removeProfileInOrganize(profile.id, "OFFICER"); const clearProfile = await checkCommandType(String(item.commandId)); const _null: any = null; - if (clearProfile) { + if (clearProfile.status) { if (_profile.keycloak != null) { const delUserKeycloak = await deleteUser(_profile.keycloak); if (delUserKeycloak) { @@ -3860,6 +3890,11 @@ export class CommandController extends Controller { _profile.isActive = false; } } + _profile.leaveCommandId = item.commandId ?? _null; + _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveRemark = clearProfile.leaveRemark ?? _null; + _profile.leaveDate = item.date ?? _null; + _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; _profile.posLevelId = _null; diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 0d28822d..220c4400 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -8263,6 +8263,7 @@ export class ProfileController extends Controller { if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "OFFICER"); } + profile.leaveType = "RETIRE_DECEASED"; 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 18ea3b28..a4f2121a 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -3871,6 +3871,7 @@ export class ProfileEmployeeController extends Controller { if (requestBody.isLeave == true) { await removeProfileInOrganize(profile.id, "EMPLOYEE"); } + profile.leaveType = "RETIRE_DECEASED"; await this.profileRepo.save(profile); return new HttpSuccess(); diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 1fbcfb14..30e33830 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -10,6 +10,7 @@ import { Command } from "../entities/Command"; import { ProfileSalary } from "../entities/ProfileSalary"; import { Profile } from "../entities/Profile"; import { ProfileEmployee } from "../entities/ProfileEmployee"; +import { CommandRecive } from "../entities/CommandRecive"; export function calculateAge(start: Date, end = new Date()) { if (start.getTime() > end.getTime()) return null; @@ -347,20 +348,62 @@ export async function checkExceptCommandType(commandId: string) { export async function checkCommandType(commandId: string) { const commandRepository = AppDataSource.getRepository(Command); + const commandReciveRepository = AppDataSource.getRepository(CommandRecive) const _type = await commandRepository.findOne({ where: { id: commandId, }, - relations: ["commandType"], + relations: ["commandType", "commandRecives"], }); + if ( !["C-PM-12", "C-PM-13", "C-PM-17", "C-PM-18", "C-PM-23", "C-PM-19", "C-PM-20"].includes( String(_type?.commandType.code), ) ) { - return false; + // return false; + return { status: false, LeaveType: null, leaveRemark: null}; } - return true; + // return true; + const _commandRecive = await commandReciveRepository.findOne({ + where: { commandId: commandId } + }); + + let _leaveType: string ="" + switch(String(_type?.commandType.code)){ + case "C-PM-12" : { + _leaveType = "PROBATION_REPORT"; + break; + } + case "C-PM-13" : { + _leaveType = "PLACEMENT_TRANSFER"; + break; + } + case "C-PM-17" : { + _leaveType = "RETIRE_RESIGN"; + break; + } + case "C-PM-18" : { + _leaveType = "RETIRE_OUT"; + break; + } + case "C-PM-19" : { + _leaveType = "DISCIPLINE_RESULT_REMOVE"; + break; + } + case "C-PM-20" : { + _leaveType = "DISCIPLINE_RESULT_DISMISS"; + break; + } + case "C-PM-23" : { + _leaveType = "RETIRE_RESIGN_EMP"; + break; + } + default: { + _leaveType = "" + } + } + return { status: true, LeaveType: _leaveType, leaveRemark: _commandRecive ? _commandRecive.remarkVertical : null }; } //logs