From 16324a09fd654e61663e194c1a78d1fb700074f5 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 27 Feb 2024 17:30:37 +0700 Subject: [PATCH] no message --- src/controllers/OrganizationController.ts | 32 +++++++ src/controllers/ProfileController.ts | 105 ++++++++++++++++++---- 2 files changed, 121 insertions(+), 16 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 7fc8296a..dd16096d 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -2831,4 +2831,36 @@ export class OrganizationController extends Controller { return error; } } + + /** + * API หาสำนักทั้งหมด + * + * @summary หาสำนักทั้งหมด + * + */ + @Get("active/root") + async GetActiveRoot() { + try { + const orgRevisionActive = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, + }); + if (!orgRevisionActive) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร๋อยู่ตอนนี้"); + } + + const data = await this.orgRootRepository.find({ + where: { orgRevisionId: orgRevisionActive.id }, + relations: [ + "orgRevision", + "orgChild1s", + "orgChild1s.orgChild2s", + "orgChild1s.orgChild2s.orgChild3s", + "orgChild1s.orgChild2s.orgChild3s.orgChild4s", + ], + }); + return new HttpSuccess(data); + } catch (error) { + return error; + } + } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index d5fb8c85..cc2ed80d 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -255,10 +255,10 @@ export class ProfileController extends Controller { * */ @Get() - async listProfile( - @Query("page") page: number = 1, - @Query("pageSize") pageSize: number = 10, - @Query("keyword") keyword?: string, + async listProfile( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, ) { const [profile, total] = await this.profileRepository.findAndCount({ select: [ @@ -279,15 +279,9 @@ export class ProfileController extends Controller { const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, ""); const filteredProfile = profile.filter( (x) => - ( - x.prefix + - x.firstName + - x.lastName - ) - .replace(/\s+/g, "") - .includes(formattedKeyword) || + (x.prefix + x.firstName + x.lastName).replace(/\s+/g, "").includes(formattedKeyword) || x.citizenId?.toString().includes(keyword) || - x.position?.toString().includes(keyword) + x.position?.toString().includes(keyword), ); const formattedData = filteredProfile.map((item) => ({ @@ -298,7 +292,7 @@ export class ProfileController extends Controller { citizenId: item.citizenId, position: item.position, posLevelId: item.posLevelId, - posTypeId: item.posTypeId + posTypeId: item.posTypeId, })); return new HttpSuccess({ data: formattedData, total: formattedData.length }); @@ -316,10 +310,9 @@ export class ProfileController extends Controller { citizenId: item.citizenId, position: item.position, posLevelId: item.posLevelId, - posTypeId: item.posTypeId + posTypeId: item.posTypeId, })); return new HttpSuccess({ data: formattedData, total }); - } /** @@ -454,11 +447,21 @@ export class ProfileController extends Controller { async getProfileByKeycloak(@Request() request: { user: Record }) { const profile = await this.profileRepository.findOne({ where: { keycloak: request.user.sub }, - relations: ["posLevel", "posType"], + relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"], }); if (!profile) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const orgRevisionPublish = await this.orgRevisionRepository + .createQueryBuilder("orgRevision") + .where("orgRevision.orgRevisionIsDraft = false") + .andWhere("orgRevision.orgRevisionIsCurrent = true") + .getOne(); + if (!orgRevisionPublish) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง"); } + const _profile = { profileId: profile.id, prefix: profile.prefix, @@ -472,6 +475,76 @@ export class ProfileController extends Controller { 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 == orgRevisionPublish.id)?.orgRoot == + null + ? null + : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) + ?.orgRootId, + 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 + .orgRootName, + child1Id: + 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) + ?.orgChild1Id, + 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 + .orgChild1Name, + child2Id: + 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) + ?.orgChild2Id, + 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 + .orgChild2Name, + child3Id: + 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) + ?.orgChild3Id, + 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 + .orgChild3Name, + child4Id: + 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) + ?.orgChild4Id, + 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 + .orgChild4Name, }; try { return new HttpSuccess(_profile);