From e8b14c648e6d3605b1574238d947aee391853578 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 10:33:51 +0700 Subject: [PATCH] =?UTF-8?q?api=20=E0=B9=82=E0=B8=84=E0=B8=A3=E0=B8=87?= =?UTF-8?q?=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=A5=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=AA=E0=B8=B8=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 41 ++++++++ src/controllers/ProfileController.ts | 123 ++++++++++++++++++++-- 2 files changed, 155 insertions(+), 9 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index dd16096d..9ed4c139 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -2863,4 +2863,45 @@ export class OrganizationController extends Controller { return error; } } + + /** + * API หาสำนักทั้งหมด by revision + * + * @summary หาสำนักทั้งหมด by revision + * + */ + @Get("active/root/{revisionId}") + async GetActiveRootByRevision(@Path() revisionId: string) { + try { + const data = await this.orgRootRepository.find({ + where: { orgRevisionId: revisionId }, + relations: [ + "orgRevision", + "orgChild1s", + "orgChild1s.orgChild2s", + "orgChild1s.orgChild2s.orgChild3s", + "orgChild1s.orgChild2s.orgChild3s.orgChild4s", + ], + }); + return new HttpSuccess(data); + } catch (error) { + return error; + } + } + /** + * API หา revision ล่าสุด + * + * @summary หา revision ล่าสุด + * + */ + @Get("revision/latest") + async salaryGen() { + const findRevision = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างล่าสุด"); + } + return new HttpSuccess(findRevision.id); + } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 477ba65d..9238069a 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -991,19 +991,19 @@ export class ProfileController extends Controller { } const posExecutive = item.positions == null || - item.positions?.find((position) => position.positionIsSelected ==true) == null || - item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive == null || - item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive?.posExecutiveName == null + item.positions?.find((position) => position.positionIsSelected == true) == null || + item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive == + null || + item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive + ?.posExecutiveName == null ? null - : item.positions?.find((position) => position.positionIsSelected ==true)?.posExecutive + : item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive .posExecutiveName; - const amount = - item.current_holder == null || - item.current_holder.profileSalary.length == 0 - ? null - : item.current_holder.profileSalary.sort((a:any, b:any) => b.date - a.date)[0].amount; + item.current_holder == null || item.current_holder.profileSalary.length == 0 + ? null + : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount; return { prefix: item.current_holder.prefix, @@ -1019,6 +1019,7 @@ export class ProfileController extends Controller { posLevelId: item.current_holder.posLevelId, posExecutive: posExecutive, amount: amount, + revisionId: item.orgRevisionId, rootId: item.orgRootId, root: item.orgRoot?.orgRootName, child1Id: item.orgChild1Id, @@ -1039,4 +1040,108 @@ export class ProfileController extends Controller { return new HttpSuccess(formattedData); } + + /** + * API ข้อมูลทะเบียนประวัติตาม keycloak by revisionId + * + * @summary ข้อมูลทะเบียนประวัติตาม keycloak by revisionId (ADMIN) + * + */ + @Get("keycloak/position/{revisionId}") + async getProfileByKeycloakByRevision( + @Path() revisionId: string, + @Request() request: { user: Record }, + ) { + const profile = await this.profileRepository.findOne({ + where: { keycloak: request.user.sub }, + relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], + }); + if (!profile) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const _profile = { + profileId: profile.id, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + citizenId: profile.citizenId, + position: profile.position, + 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: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRootId, + root: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgRoot.orgRootName, + child1Id: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1Id, + child1: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild1 + .orgChild1Name, + child2Id: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2Id, + child2: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild2 + .orgChild2Name, + child3Id: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3Id, + child3: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild3 + .orgChild3Name, + child4Id: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4Id, + child4: + profile.current_holders == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId) == null || + profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 == null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == revisionId)?.orgChild4 + .orgChild4Name, + }; + try { + return new HttpSuccess(_profile); + } catch (error: any) { + throw new Error(error); + } + } }