From f7f6db43b1fd8bf25744cf7b74e568e2b1e84fad Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 2 May 2024 09:29:27 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2?= =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99?= =?UTF-8?q?=20by=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OrganizationUnauthorizeController.ts | 6 +- src/controllers/ProfileController.ts | 116 ++++++++++++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index fc9351b8..6be5ae66 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -717,6 +717,7 @@ export class OrganizationUnauthorizeController extends Controller { let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; + let _root = root == null ? "" : `${root.orgRootName}`; return new HttpSuccess({ rootId: root == null ? null : root.id, @@ -724,7 +725,7 @@ export class OrganizationUnauthorizeController extends Controller { orgRootShortName: root == null ? null : root.orgRootShortName, orgRevisionId: findRevision.id, profileId: findProfile.id, - org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName}`, + org: `${_child4}${_child3}${_child2}${_child1}${_root}`, type: "OFFICER", rank: findProfile.rank, prefix: findProfile.prefix, @@ -808,6 +809,7 @@ export class OrganizationUnauthorizeController extends Controller { let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`; let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`; let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`; + let _root = root == null ? "" : `${root.orgRootName}`; return new HttpSuccess({ rootId: root == null ? null : root.id, @@ -815,7 +817,7 @@ export class OrganizationUnauthorizeController extends Controller { orgRootShortName: root == null ? null : root.orgRootShortName, orgRevisionId: findRevision.id, profileId: findProfile.id, - org: `${_child4}${_child3}${_child2}${_child1}${root?.orgRootName}`, + org: `${_child4}${_child3}${_child2}${_child1}${_root}`, type: "EMPLOYEE", rank: findProfile.rank, prefix: findProfile.prefix, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 3d299417..14671f3e 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -818,6 +818,122 @@ export class ProfileController extends Controller { return new HttpSuccess(_profile); } + /** + * API ข้อมูลทะเบียนประวัติตาม profileid + * + * @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม profileid (ADMIN) #70 + * + */ + @Get("profileid/position/{id}") + async getProfileByProfileid( + @Request() request: { user: Record }, + @Path() id: string, + ) { + const profile = await this.profileRepo.findOne({ + where: { id: id }, + relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const orgRevisionPublish = await this.orgRevisionRepo + .createQueryBuilder("orgRevision") + .where("orgRevision.orgRevisionIsDraft = false") + .andWhere("orgRevision.orgRevisionIsCurrent = true") + .getOne(); + if (!orgRevisionPublish) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); + } + + const posMaster = + profile.current_holders == null || + profile.current_holders.length == 0 || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id); + const root = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot; + const child1 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1; + const child2 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2; + const child3 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3; + const child4 = + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4; + const _profile: any = { + profileId: profile.id, + prefix: profile.prefix, + rank: profile.rank, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + posMasterNo: posMaster == null ? null : posMaster.posMasterNo, + posLevelName: profile.posLevel == null ? null : profile.posLevel.posLevelName, + posLevelRank: profile.posLevel == null ? null : profile.posLevel.posLevelRank, + posLevelId: profile.posLevel == null ? null : profile.posLevel.id, + posTypeName: profile.posType == null ? null : profile.posType.posTypeName, + posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank, + posTypeId: profile.posType == null ? null : profile.posType.id, + rootId: root == null ? null : root.id, + root: root == null ? null : root.orgRootName, + rootShortName: root == null ? null : root.orgRootShortName, + child1Id: child1 == null ? null : child1.id, + child1: child1 == null ? null : child1.orgChild1Name, + child1ShortName: child1 == null ? null : child1.orgChild1ShortName, + child2Id: child2 == null ? null : child2.id, + child2: child2 == null ? null : child2.orgChild2Name, + child2ShortName: child2 == null ? null : child2.orgChild2ShortName, + child3Id: child3 == null ? null : child3.id, + child3: child3 == null ? null : child3.orgChild3Name, + child3ShortName: child3 == null ? null : child3.orgChild3ShortName, + child4Id: child4 == null ? null : child4.id, + child4: child4 == null ? null : child4.orgChild4Name, + child4ShortName: child4 == null ? null : child4.orgChild4ShortName, + node: null, + nodeId: null, + }; + + if (_profile.child4Id != null) { + _profile.node = 4; + _profile.nodeId = _profile.child4Id; + } else if (_profile.child3Id != null) { + _profile.node = 3; + _profile.nodeId = _profile.child3Id; + } else if (_profile.child2Id != null) { + _profile.node = 2; + _profile.nodeId = _profile.child2Id; + } else if (_profile.child1Id != null) { + _profile.node = 1; + _profile.nodeId = _profile.child1Id; + } else if (_profile.rootId != null) { + _profile.node = 0; + _profile.nodeId = _profile.rootId; + } + return new HttpSuccess(_profile); + } + /** * API ค้นหาข้อมูลทะเบียนประวัติ *