From 769352b4c2c6affb275b7b42bc57ea89414c336e Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 2 May 2024 17:54:01 +0700 Subject: [PATCH] api get profile by citizen --- src/controllers/ProfileController.ts | 127 ++++++++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index fa43a55e..c3c6e15f 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -935,13 +935,134 @@ export class ProfileController extends Controller { } /** - * API ข้อมูลทะเบียนประวัติตาม profileid + * API ข้อมูลทะเบียนประวัติตาม citizenId * - * @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม profileid (ADMIN) #70 + * @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม citizenId (ADMIN) #70 + * + */ + @Get("citizenid/position/{id}") + async getProfileByCitizenId( + @Request() request: { user: Record }, + @Path() id: string, + ) { + const profile = await this.profileRepo.findOne({ + where: { citizenId: 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; + _profile.nodeShortName = _profile.child4ShortName; + } else if (_profile.child3Id != null) { + _profile.node = 3; + _profile.nodeId = _profile.child3Id; + _profile.nodeShortName = _profile.child3ShortName; + } else if (_profile.child2Id != null) { + _profile.node = 2; + _profile.nodeId = _profile.child2Id; + _profile.nodeShortName = _profile.child2ShortName; + } else if (_profile.child1Id != null) { + _profile.node = 1; + _profile.nodeId = _profile.child1Id; + _profile.nodeShortName = _profile.child1ShortName; + } else if (_profile.rootId != null) { + _profile.node = 0; + _profile.nodeId = _profile.rootId; + _profile.nodeShortName = _profile.rootShortName; + } + return new HttpSuccess(_profile); + } + + /** + * API ข้อมูลทะเบียนประวัติตาม profileempid + * + * @summary ORG_065 - ข้อมูลทะเบียนประวัติตาม profileempid (ADMIN) #70 * */ @Get("profileempid/position/{id}") - async getProfileEmpByProfileid( + async getProfileByProfileempid( @Request() request: { user: Record }, @Path() id: string, ) {