From f7cca938779004a9fb012a054f06b98c1ee125c5 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 29 Apr 2025 10:48:33 +0700 Subject: [PATCH] =?UTF-8?q?add=20=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=A7?= =?UTF-8?q?=E0=B8=A2=E0=B8=87=E0=B8=B2=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87(=E0=B8=95=E0=B8=B1=E0=B8=A7=E0=B8=A2?= =?UTF-8?q?=E0=B9=88=E0=B8=AD)=20(issue=20#1459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 442 +++++++++++++++--- src/controllers/ProfileSalaryController.ts | 40 +- .../ProfileSalaryEmployeeController.ts | 38 +- 3 files changed, 458 insertions(+), 62 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 4106bb1a..b94506a0 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -85,7 +85,7 @@ import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; - +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/command") @Tags("Command") @Security("bearerAuth") @@ -134,6 +134,7 @@ export class CommandController extends Controller { private profileFamilyMotherHistoryRepo = AppDataSource.getRepository(ProfileFamilyMotherHistory); private profileFamilyFatherRepo = AppDataSource.getRepository(ProfileFamilyFather); private profileFamilyFatherHistoryRepo = AppDataSource.getRepository(ProfileFamilyFatherHistory); + private orgRootRepository = AppDataSource.getRepository(OrgRoot); /** * API list รายการคำสั่ง @@ -2953,19 +2954,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -2992,6 +3020,7 @@ export class CommandController extends Controller { lastUpdatedAt: new Date(), }; data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; Object.assign(data, { ...item, ...meta }); const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); @@ -3101,19 +3130,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -3130,6 +3186,7 @@ export class CommandController extends Controller { const before = null; const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { order: dest_item == null ? 1 : dest_item.order + 1, createdUserId: req.user.sub, @@ -3268,19 +3325,46 @@ export class CommandController extends Controller { where: { name: Like("USER") }, }); let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -3310,6 +3394,7 @@ export class CommandController extends Controller { lastUpdatedAt: new Date(), }; data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; Object.assign(data, { ...item, ...meta }); const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); @@ -3457,19 +3542,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -3489,6 +3601,7 @@ export class CommandController extends Controller { const before = null; const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { order: dest_item == null ? 1 : dest_item.order + 1, createdUserId: req.user.sub, @@ -3590,19 +3703,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -3622,6 +3762,7 @@ export class CommandController extends Controller { const before = null; const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { order: dest_item == null ? 1 : dest_item.order + 1, createdUserId: req.user.sub, @@ -3871,19 +4012,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -3960,6 +4128,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileId: profile.id, commandId: item.commandId, @@ -4154,6 +4323,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileEmployeeId: profile.id, commandId: item.commandId, @@ -4323,19 +4493,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -4410,6 +4607,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileEmployeeId: profile.id, commandId: item.commandId, @@ -4567,19 +4765,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -4655,6 +4880,7 @@ export class CommandController extends Controller { // ประวัติตำแหน่ง const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileId: item.profileId, commandId: item.commandId, @@ -4743,19 +4969,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -4883,7 +5136,8 @@ export class CommandController extends Controller { commandCode: item.commandCode, commandName: item.commandName, remark: item.remark, - posNumCodeSit: _posNumCodeSit + posNumCodeSit: _posNumCodeSit, + posNumCodeSitAbb: _posNumCodeSitAbb }); await removeProfileInOrganize(profile.id, "OFFICER"); const clearProfile = await checkCommandType(String(item.commandId)); @@ -4966,21 +5220,46 @@ export class CommandController extends Controller { if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); const _null: any = null; let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ - where: { - id: body.data.find(x => x.bodySalarys?.commandId)?.bodySalarys?.commandId ?? "" - } + where: { id: body.data.find(x => x.bodySalarys?.commandId)?.bodySalarys?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -5274,6 +5553,7 @@ export class CommandController extends Controller { }); const profileSal: any = new ProfileSalary(); profileSal.posNumCodeSit = _posNumCodeSit; + profileSal.posNumCodeSitAbb = _posNumCodeSitAbb; Object.assign(profileSal, { ...item.bodySalarys, ...meta }); const salaryHistory = new ProfileSalaryHistory(); Object.assign(salaryHistory, { ...profileSal, id: undefined }); @@ -5445,19 +5725,46 @@ export class CommandController extends Controller { where: { name: Like("USER") }, }); let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -5510,6 +5817,7 @@ export class CommandController extends Controller { const before = null; const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileEmployeeId: profile.id, amount: item.amount, @@ -5967,19 +6275,46 @@ export class CommandController extends Controller { }, ) { let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } await Promise.all( @@ -6035,6 +6370,7 @@ export class CommandController extends Controller { const before = null; const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { profileId: profile?.id, date: new Date(), diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 908a599d..b73a1eda 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -28,6 +28,7 @@ import { TenureLevelOfficer } from "../entities/TenureLevelOfficer"; import { TenurePositionEmployee } from "../entities/TenurePositionEmployee"; import { TenureLevelEmployee } from "../entities/TenureLevelEmployee"; import { Command } from "../entities/Command"; +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/profile/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -41,7 +42,8 @@ export class ProfileSalaryController extends Controller { private levelOfficerRepo = AppDataSource.getRepository(TenureLevelOfficer); private levelEmployeeRepo = AppDataSource.getRepository(TenureLevelEmployee); private commandRepository = AppDataSource.getRepository(Command); - + private orgRootRepository = AppDataSource.getRepository(OrgRoot); + @Get("TenurePositionOfficer") public async cronjobTenurePositionOfficer() { let data: any = []; @@ -674,23 +676,51 @@ export class ProfileSalaryController extends Controller { }); const before = null; let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileRepo.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { order: dest_item == null ? 1 : dest_item.order + 1, createdUserId: req.user.sub, diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 6ffecd18..71413455 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -28,6 +28,7 @@ import { In, LessThan, MoreThan } from "typeorm"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { Command } from "../entities/Command"; +import { OrgRoot } from "../entities/OrgRoot"; @Route("api/v1/org/profile-employee/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -37,6 +38,7 @@ export class ProfileSalaryEmployeeController extends Controller { private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); private commandRepository = AppDataSource.getRepository(Command); + private orgRootRepository = AppDataSource.getRepository(OrgRoot); @Get("user") public async getSalaryUser(@Request() request: { user: Record }) { @@ -358,23 +360,51 @@ export class ProfileSalaryEmployeeController extends Controller { }); const before = null; let _posNumCodeSit: string = "" + let _posNumCodeSitAbb: string = "" const _command = await this.commandRepository.findOne({ where: { id: body.commandId ?? "" } }); if (_command) { - if (_command?.isBangkok == "OFFICE") _posNumCodeSit = "สำนักปลัดกรุงเทพมหานคร" - else if (_command?.isBangkok == "BANGKOK") _posNumCodeSit = "กรุงเทพมหานคร" + if (_command?.isBangkok.toLocaleUpperCase() == "OFFICE") { + const orgRootDeputy = await this.orgRootRepository.findOne({ + where: { + isDeputy: true, + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + }, + relations: ["orgRevision"] + }) + _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; + _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; + } + else if (_command?.isBangkok.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร" + _posNumCodeSitAbb = "กทม." + } else { let _profileAdmin = await this.profileGovementRepo.findOne({ - where: { keycloak: _command?.createdUserId.toString()}, - relations: ["current_holders", "current_holders.orgRoot",] + where: { + keycloak: _command?.createdUserId.toString(), + current_holders: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false + } + } + }, + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] }); _posNumCodeSit = _profileAdmin?.current_holders .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" + _posNumCodeSitAbb = _profileAdmin?.current_holders + .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" } } const data = new ProfileSalary(); data.posNumCodeSit = _posNumCodeSit; + data.posNumCodeSitAbb = _posNumCodeSitAbb; const meta = { order: dest_item == null ? 1 : dest_item.order + 1, createdUserId: req.user.sub,