From 932d4b94e95fcaeca54d8763d1256597cde44696 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 16 Aug 2024 14:19:02 +0700 Subject: [PATCH] no message --- src/controllers/ProfileController.ts | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 5852b7b8..c4212bd2 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -60,6 +60,7 @@ import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory"; import { ProfileLeave } from "../entities/ProfileLeave"; import { updateName } from "../keycloak"; import permission from "../interfaces/permission"; +import { PosMasterAct } from "../entities/PosMasterAct"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -97,6 +98,8 @@ export class ProfileController extends Controller { private profileDisciplineRepo = AppDataSource.getRepository(ProfileDiscipline); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave); + private posMasterActRepository = AppDataSource.getRepository(PosMasterAct); + /** * report ประวัติแบบย่อ ข้าราชการ * @@ -3167,6 +3170,58 @@ export class ProfileController extends Controller { ?.orgRoot != null ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot.orgRootShortName}${profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.posMasterNo}` : null; + const posMasterActs = await this.posMasterActRepository.find({ + relations: [ + "posMaster", + "posMaster.orgRoot", + "posMaster.orgChild1", + "posMaster.orgChild2", + "posMaster.orgChild3", + "posMaster.orgChild4", + "posMaster.current_holder", + "posMaster.current_holder.posLevel", + "posMaster.current_holder.posType", + ], + where: { + posMaster: { + orgRevisionId: orgRevisionPublish.id, + }, + posMasterChild: { + current_holderId: profile.id, + }, + }, + }); + const data = await Promise.all( + posMasterActs + .sort((a, b) => a.posMaster.posMasterOrder - b.posMaster.posMasterOrder) + .map((item) => { + const shortName = + item.posMaster != null && item.posMaster.orgChild4 != null + ? `${item.posMaster.orgChild4.orgChild4ShortName}${item.posMaster.posMasterNo}` + : item.posMaster != null && item.posMaster?.orgChild3 != null + ? `${item.posMaster.orgChild3.orgChild3ShortName}${item.posMaster.posMasterNo}` + : item.posMaster != null && item.posMaster?.orgChild2 != null + ? `${item.posMaster.orgChild2.orgChild2ShortName}${item.posMaster.posMasterNo}` + : item.posMaster != null && item.posMaster?.orgChild1 != null + ? `${item.posMaster.orgChild1.orgChild1ShortName}${item.posMaster.posMasterNo}` + : item.posMaster != null && item.posMaster?.orgRoot != null + ? `${item.posMaster.orgRoot.orgRootShortName}${item.posMaster.posMasterNo}` + : null; + return { + id: item.id, + posMasterOrder: item.posMasterOrder, + profileId: item.posMaster?.current_holder?.id ?? null, + citizenId: item.posMaster?.current_holder?.citizenId ?? null, + prefix: item.posMaster?.current_holder?.prefix ?? null, + firstName: item.posMaster?.current_holder?.firstName ?? null, + lastName: item.posMaster?.current_holder?.lastName ?? null, + posLevel: item.posMaster?.current_holder?.posLevel?.posLevelName ?? null, + posType: item.posMaster?.current_holder?.posType?.posTypeName ?? null, + position: item.posMaster?.current_holder?.position ?? null, + posNo: shortName, + }; + }), + ); const _profile: any = { profileId: profile.id, prefix: profile.prefix, @@ -3207,6 +3262,8 @@ export class ProfileController extends Controller { node: null, nodeId: null, posNo: shortName, + isPosmasterAct: data.length > 0, + posmasterAct: data, }; if (_profile.child4Id != null) {