From 124e6ea1d72350565df4f1afee9048ee8597077f Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 14:58:28 +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?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 68 +++++++++++++++++++--------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index cdde0201..55d079de 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -333,31 +333,13 @@ export class ProfileController extends Controller { .leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posType", "posType") .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("current_holders.positions", "positions") + .leftJoinAndSelect("positions.posExecutive", "posExecutive") .leftJoinAndSelect("current_holders.orgRoot", "orgRoot") .leftJoinAndSelect("current_holders.orgChild1", "orgChild1") .leftJoinAndSelect("current_holders.orgChild2", "orgChild2") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4") - .select([ - "profile.id", - "profile.rank", - "profile.prefix", - "profile.firstName", - "profile.lastName", - "profile.citizenId", - "profile.birthDate", - "profile.isProbation", - "profile.dateRetire", - "profile.position", - "posType.posTypeName", - "posLevel.posLevelName", - "current_holders.posMasterNo", - // "orgRoot?.orgRootShortName", - // "orgChild1?.orgRootShortName", - // "orgChild2?.orgRootShortName", - // "orgChild3?.orgRootShortName", - // "orgChild4?.orgRootShortName", - ]) .andWhere( searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? queryLike @@ -397,8 +379,52 @@ export class ProfileController extends Controller { .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); + const data = await Promise.all( + record.map((_data) => { + const posExecutive = + _data.current_holders.length == 0 || + _data.current_holders[0].positions.length == 0 || + _data.current_holders[0].positions.find((x: any) => x.positionIsSelected == true) == + null || + _data.current_holders[0].positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive == null + ? null + : _data.current_holders[0].positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive?.posExecutiveName; - return new HttpSuccess({ data: record, total }); + const shortName = + _data.current_holders.length == 0 + ? null + : _data.current_holders[0].orgChild4 != null + ? `${_data.current_holders[0].orgChild4.orgChild4ShortName}${_data.current_holders[0].posMasterNo}` + : _data.current_holders[0].orgChild3 != null + ? `${_data.current_holders[0].orgChild3.orgChild3ShortName}${_data.current_holders[0].posMasterNo}` + : _data.current_holders[0].orgChild2 != null + ? `${_data.current_holders[0].orgChild2.orgChild2ShortName}${_data.current_holders[0].posMasterNo}` + : _data.current_holders[0].orgChild1 != null + ? `${_data.current_holders[0].orgChild1.orgChild1ShortName}${_data.current_holders[0].posMasterNo}` + : _data.current_holders[0].orgRoot != null + ? `${_data.current_holders[0].orgRoot.orgRootShortName}${_data.current_holders[0].posMasterNo}` + : null; + return { + id: _data.id, + prefix: _data.prefix, + rank: _data.rank, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, + posTypeId: _data.posType == null ? null : _data.posType.id, + position: _data.position, + posExecutive: posExecutive, + posNo: shortName, + }; + }), + ); + + return new HttpSuccess({ data: data, total }); } /**