From 3a4e16deb0946964e1caeb8eb1ee3b419c64b1ca Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Fri, 12 Dec 2025 01:36:51 +0700 Subject: [PATCH 01/14] add permission brother --- src/controllers/OrganizationController.ts | 4 +-- .../OrganizationDotnetController.ts | 27 +++++++------------ src/controllers/PermissionController.ts | 8 ++++++ src/controllers/PositionController.ts | 8 ++++-- src/interfaces/permission.ts | 9 +++++++ 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 04a2fa7e..edbd1f97 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -2036,7 +2036,7 @@ export class OrganizationController extends Controller { _data.child2 = [holder.orgChild2Id]; _data.child3 = [holder.orgChild3Id]; _data.child4 = [holder.orgChild4Id]; - } else if (_privilege.privilege == "CHILD") { + } else if (_privilege.privilege == "CHILD" || _privilege.privilege == "BROTHER") { const holder = profile.current_holders.find((x) => x.orgRevisionId === id); if (!holder) return; _data.root = [holder.orgRootId]; @@ -6174,7 +6174,7 @@ export class OrganizationController extends Controller { _data.child2 = [holder.orgChild2Id]; _data.child3 = [holder.orgChild3Id]; _data.child4 = [holder.orgChild4Id]; - } else if (_privilege.privilege == "CHILD") { + } else if (_privilege.privilege == "CHILD" || _privilege.privilege == "BROTHER") { const holder = profile.current_holders.find((x) => x.orgRevisionId === id); if (!holder) return; _data.root = [holder.orgRootId]; diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index cbae3874..00eb9b5a 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -79,7 +79,7 @@ export class OrganizationDotnetController extends Controller { ) { let condition = "1=1"; let conditionParams = {}; - if (body.role === "CHILD") { + if (body.role === "CHILD" || body.role === "BROTHER") { switch (body.node) { case 0: condition = "orgRoot.ancestorDNA = :nodeId"; @@ -198,7 +198,7 @@ export class OrganizationDotnetController extends Controller { ) { let condition = "1=1"; let conditionParams = {}; - if (body.role === "CHILD") { + if (body.role === "CHILD" || body.role === "BROTHER") { switch (body.node) { case 0: condition = "orgRoot.ancestorDNA = :nodeId"; @@ -4399,8 +4399,8 @@ export class OrganizationDotnetController extends Controller { }, ) { let typeCondition: any = {}; - if (body.role === "CHILD" || body.role === "PARENT") { - if (body.role === "CHILD") { + if (body.role === "CHILD" || body.role === "PARENT" || body.role === "BROTHER") { + if (body.role === "CHILD" || body.role === "BROTHER") { switch (body.node) { case 0: typeCondition = { @@ -4441,16 +4441,14 @@ export class OrganizationDotnetController extends Controller { typeCondition = {}; break; } - } - else if (body.role === "PARENT") { + } else if (body.role === "PARENT") { typeCondition = { orgRoot: { - ancestorDNA: body.nodeId + ancestorDNA: body.nodeId, }, orgChild1: Not(IsNull()), }; } - } else if (body.role === "OWNER" || body.role === "ROOT") { switch (body.reqNode) { case 0: @@ -5005,8 +5003,8 @@ export class OrganizationDotnetController extends Controller { }, ) { let typeCondition: any = {}; - if (body.role === "CHILD" || body.role === "PARENT") { - if (body.role === "CHILD") { + if (body.role === "CHILD" || body.role === "PARENT" || body.role === "BROTHER") { + if (body.role === "CHILD" || body.role === "BROTHER") { switch (body.node) { case 0: typeCondition = { @@ -5043,23 +5041,18 @@ export class OrganizationDotnetController extends Controller { }, }; break; - case null: - typeCondition = {}; - break; default: typeCondition = {}; break; } - } - else if (body.role === "PARENT") { + } else if (body.role === "PARENT") { typeCondition = { orgRoot: { - ancestorDNA: body.nodeId + ancestorDNA: body.nodeId, }, orgChild1: Not(IsNull()), }; } - } else if (body.role === "OWNER" || body.role === "ROOT") { switch (body.reqNode) { case 0: diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 4cd20c8b..b082f0fd 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -748,6 +748,14 @@ export class PermissionController extends Controller { child3: node >= 3 ? [x.orgChild3Id] : null, child4: node >= 4 ? [x.orgChild4Id] : null, }; + } else if (privilege == "BROTHER") { + data = { + // root: node >= 0 ? null : null, + root: node >= 0 ? [x.orgRootId] : null, + child1: node >= 2 ? [x.orgChild1Id] : null, + child2: node >= 3 ? [x.orgChild2Id] : null, + child3: node >= 4 ? [x.orgChild3Id] : null, + }; } else if (privilege == "NORMAL") { data = { root: [x.orgRootId], diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 84144021..d2c5fc87 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2525,7 +2525,11 @@ export class PositionController extends Controller { }), ); - if (_data.privilege === "NORMAL" || _data.privilege === "CHILD") { + if ( + _data.privilege === "NORMAL" || + _data.privilege === "CHILD" || + _data.privilege === "BROTHER" + ) { //PARENT จะไม่มีทางเห็น ROOT , CHILD ยึดจาก CHILD ที่อยู่ลงไปข้างล่างและจะไม่เห็น CHILD ที่อยู่เหนือกว่า const nextChildMap: any = { //เอาไวเช็ค CHILD ถัดไป @@ -2539,7 +2543,7 @@ export class PositionController extends Controller { if (Array.isArray(childValue) && childValue.some((item) => item != null)) { return new HttpSuccess({ data: [], total: 0 }); } - } else if (_data.privilege === "CHILD") { + } else if (_data.privilege === "CHILD" || _data.privilege === "BROTHER") { const higherChildChecks = [ { type: [0], child: _data.child1, next: _data.child2 }, { type: [0, 1], child: _data.child2, next: _data.child3 }, diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index b48478dc..1542ce45 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -112,6 +112,15 @@ class CheckAuth { child4: node >= 4 ? [x.orgChild4Id] : null, privilege: "CHILD", }; + } else if (privilege == "BROTHER") { + data = { + // root: node >= 0 ? [x.orgRootId] : null, + root: node >= 0 ? [x.orgRootId] : null, + child1: node >= 2 ? [x.orgChild1Id] : null, + child2: node >= 3 ? [x.orgChild2Id] : null, + child3: node >= 4 ? [x.orgChild3Id] : null, + privilege: "BROTHER", + }; } else if (privilege == "NORMAL") { data = { root: [x.orgRootId], From 5e9189a4892cae8e49d39ff56c1cc29e882ff841 Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 12 Dec 2025 18:27:32 +0700 Subject: [PATCH 02/14] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=9F=E0=B8=B4=E0=B8=A5=E0=B8=94=E0=B9=8C=20isSala?= =?UTF-8?q?ry=20+=20api=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7?= =?UTF-8?q?=E0=B8=AD=E0=B8=99=E0=B8=97=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B8=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=20=20#2102?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 48 ++++++++++++++++++++++++ src/controllers/CommandTypeController.ts | 1 + src/controllers/WorkflowController.ts | 4 +- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index cad8dc18..a682932d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -649,6 +649,54 @@ export class CommandController extends Controller { return new HttpSuccess(); } + /** + * API แก้ไขเงินเดือนทั้งกลุ่ม + * + * @summary API แก้ไขเงินเดือนทั้งกลุ่ม + * + * @param {string} id Id คำสั่ง + */ + @Post("tab2/edit-salary") + async EditSalary( + @Body() + requestBody: { + id: string; + mouthSalaryAmount?: Double | null; + positionSalaryAmount?: Double | null; + amount?: Double | null; + amountSpecial?: Double | null; + remarkVertical?: string | null; + remarkHorizontal?: string | null; + }[], + @Request() request: RequestWithUser, + ) { + await new permission().PermissionUpdate(request, "COMMAND"); + + if (!Array.isArray(requestBody)) { + throw new HttpError(HttpStatusCode.BAD_REQUEST, "รูปแบบข้อมูลไม่ถูกต้อง"); + } + + for (const item of requestBody) { + if (!item.id) continue; + + const rec = await this.commandReciveRepository.findOne({ + where: { id: item.id }, + }); + + if (!rec) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง"); + } + + const updated = Object.assign(rec, item); + updated.lastUpdateUserId = request.user.sub; + updated.lastUpdateFullName = request.user.name; + updated.lastUpdatedAt = new Date(); + + await this.commandReciveRepository.save(updated); + } + return new HttpSuccess(); + } + /** * API ลบรายการผู้ได้รับคำสั่ง * diff --git a/src/controllers/CommandTypeController.ts b/src/controllers/CommandTypeController.ts index 4d12f478..6c5cc2a2 100644 --- a/src/controllers/CommandTypeController.ts +++ b/src/controllers/CommandTypeController.ts @@ -53,6 +53,7 @@ export class CommandTypeController extends Controller { "detailBody", "detailFooter", "subtitle", + "isSalary", "isAttachment", "isUploadAttachment", "createdAt", diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index e12cdd0a..884629e7 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -1030,7 +1030,7 @@ export class WorkflowController extends Controller { : data.map((x: any) => ({ ...x, posExecutiveNameOrg: - x.posExecutiveName + + x.posExecutiveName ?? "" + (x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""), })); @@ -1227,7 +1227,7 @@ export class WorkflowController extends Controller { const processedData = data.map((x: any) => ({ ...x, posExecutiveNameOrg: - x.posExecutiveName + + x.posExecutiveName ?? "" + (x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""), })); From 3111e10bfe20cecee7501fc494406d562264f4ef Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 15 Dec 2025 11:48:18 +0700 Subject: [PATCH 03/14] #2119 --- src/controllers/PositionController.ts | 132 +++++++++++++------------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index d2c5fc87..a7f2db82 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2301,52 +2301,48 @@ export class PositionController extends Controller { child4: _data.child4, }, ) - .andWhere( + .orWhere( new Brackets((qb) => { - qb.orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? body.isAll == false - ? searchShortName - : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` - : "1=1", - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), + qb.andWhere( + body.keyword != null && body.keyword != "" + ? body.isAll == false + ? searchShortName + : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` + : "1=1", ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ); + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); }), ) .orderBy("orgRoot.orgRootOrder", "ASC") @@ -2824,50 +2820,50 @@ export class PositionController extends Controller { const type0LastPosMasterNo = requestBody.type == 0 ? await this.posMasterRepository.find({ - where: { - orgRootId: requestBody.id, - orgChild1Id: IsNull(), - }, - }) + where: { + orgRootId: requestBody.id, + orgChild1Id: IsNull(), + }, + }) : []; const type1LastPosMasterNo = requestBody.type == 1 ? await this.posMasterRepository.find({ - where: { - orgChild1Id: requestBody.id, - orgChild2Id: IsNull(), - }, - }) + where: { + orgChild1Id: requestBody.id, + orgChild2Id: IsNull(), + }, + }) : []; const type2LastPosMasterNo = requestBody.type == 2 ? await this.posMasterRepository.find({ - where: { - orgChild2Id: requestBody.id, - orgChild3Id: IsNull(), - }, - }) + where: { + orgChild2Id: requestBody.id, + orgChild3Id: IsNull(), + }, + }) : []; const type3LastPosMasterNo = requestBody.type == 3 ? await this.posMasterRepository.find({ - where: { - orgChild3Id: requestBody.id, - orgChild4Id: IsNull(), - }, - }) + where: { + orgChild3Id: requestBody.id, + orgChild4Id: IsNull(), + }, + }) : []; const type4LastPosMasterNo = requestBody.type == 4 ? await this.posMasterRepository.find({ - where: { - orgChild4Id: requestBody.id, - }, - }) + where: { + orgChild4Id: requestBody.id, + }, + }) : []; const allLastPosMasterNo = [ From e20eb9e93657c01229e293793749a5521f6d1b79 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 15 Dec 2025 14:06:07 +0700 Subject: [PATCH 04/14] fix search --- src/controllers/PositionController.ts | 238 ++++++++++++++++++-------- 1 file changed, 167 insertions(+), 71 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index a7f2db82..4bfbb642 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2240,7 +2240,129 @@ export class PositionController extends Controller { }, ]; - let [posMaster, total] = await AppDataSource.getRepository(PosMaster) + //Old + // let [posMaster, total] = await AppDataSource.getRepository(PosMaster) + // .createQueryBuilder("posMaster") + // .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") + // .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") + // .leftJoinAndSelect("posMaster.orgChild2", "orgChild2") + // .leftJoinAndSelect("posMaster.orgChild3", "orgChild3") + // .leftJoinAndSelect("posMaster.orgChild4", "orgChild4") + // .leftJoinAndSelect("posMaster.current_holder", "current_holder") + // .leftJoinAndSelect("posMaster.next_holder", "next_holder") + // .leftJoinAndSelect("posMaster.orgRevision", "orgRevision") + // .where(conditions) + // .andWhere( + // _data.root != undefined && _data.root != null + // ? _data.root[0] != null + // ? `posMaster.orgRootId IN (:...root)` + // : `posMaster.orgRootId is null` + // : "1=1", + // { + // root: _data.root, + // }, + // ) + // .andWhere( + // _data.child1 != undefined && _data.child1 != null + // ? _data.child1[0] != null + // ? `posMaster.orgChild1Id IN (:...child1)` + // : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` + // : "1=1", + // { + // child1: _data.child1, + // }, + // ) + // .andWhere( + // _data.child2 != undefined && _data.child2 != null + // ? _data.child2[0] != null + // ? `posMaster.orgChild2Id IN (:...child2)` + // : `posMaster.orgChild2Id is null` + // : "1=1", + // { + // child2: _data.child2, + // }, + // ) + // .andWhere( + // _data.child3 != undefined && _data.child3 != null + // ? _data.child3[0] != null + // ? `posMaster.orgChild3Id IN (:...child3)` + // : `posMaster.orgChild3Id is null` + // : "1=1", + // { + // child3: _data.child3, + // }, + // ) + // .andWhere( + // _data.child4 != undefined && _data.child4 != null + // ? _data.child4[0] != null + // ? `posMaster.orgChild4Id IN (:...child4)` + // : `posMaster.orgChild4Id is null` + // : "1=1", + // { + // child4: _data.child4, + // }, + // ) + // .andWhere( + // new Brackets((qb) => { + // qb.orWhere( + // new Brackets((qb) => { + // qb.andWhere( + // body.keyword != null && body.keyword != "" + // ? body.isAll == false + // ? searchShortName + // : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'` + // : "1=1", + // ) + // .andWhere(checkChildConditions) + // .andWhere(typeCondition) + // .andWhere(revisionCondition); + // }), + // ) + // .orWhere( + // new Brackets((qb) => { + // qb.andWhere( + // body.keyword != null && body.keyword != "" + // ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + // : "1=1", + // { + // keyword: `%${body.keyword}%`, + // }, + // ) + // .andWhere(checkChildConditions) + // .andWhere(typeCondition) + // .andWhere(revisionCondition); + // }), + // ) + // .orWhere( + // new Brackets((qb) => { + // qb.andWhere( + // body.keyword != null && body.keyword != "" + // ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + // : "1=1", + // { + // keyword: `%${body.keyword}%`, + // }, + // ) + // .andWhere(checkChildConditions) + // .andWhere(typeCondition) + // .andWhere(revisionCondition); + // }), + // ); + // }), + // ) + // .orderBy("orgRoot.orgRootOrder", "ASC") + // .addOrderBy("orgChild1.orgChild1Order", "ASC") + // .addOrderBy("orgChild2.orgChild2Order", "ASC") + // .addOrderBy("orgChild3.orgChild3Order", "ASC") + // .addOrderBy("orgChild4.orgChild4Order", "ASC") + // .addOrderBy("posMaster.posMasterOrder", "ASC") + // .addOrderBy("posMaster.posMasterCreatedAt", "ASC") + // .skip((body.page - 1) * body.pageSize) + // .take(body.pageSize) + // .getManyAndCount(); + + //New + let query = AppDataSource.getRepository(PosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") @@ -2254,54 +2376,25 @@ export class PositionController extends Controller { .andWhere( _data.root != undefined && _data.root != null ? _data.root[0] != null - ? `posMaster.orgRootId IN (:...root)` - : `posMaster.orgRootId is null` + ? "posMaster.orgRootId IN (:...root)" + : "posMaster.orgRootId is null" : "1=1", - { - root: _data.root, - }, + { root: _data.root } ) .andWhere( _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null - ? `posMaster.orgChild1Id IN (:...child1)` + ? "posMaster.orgChild1Id IN (:...child1)" : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", - { - child1: _data.child1, - }, + { child1: _data.child1 } ) - .andWhere( - _data.child2 != undefined && _data.child2 != null - ? _data.child2[0] != null - ? `posMaster.orgChild2Id IN (:...child2)` - : `posMaster.orgChild2Id is null` - : "1=1", - { - child2: _data.child2, - }, - ) - .andWhere( - _data.child3 != undefined && _data.child3 != null - ? _data.child3[0] != null - ? `posMaster.orgChild3Id IN (:...child3)` - : `posMaster.orgChild3Id is null` - : "1=1", - { - child3: _data.child3, - }, - ) - .andWhere( - _data.child4 != undefined && _data.child4 != null - ? _data.child4[0] != null - ? `posMaster.orgChild4Id IN (:...child4)` - : `posMaster.orgChild4Id is null` - : "1=1", - { - child4: _data.child4, - }, - ) - .orWhere( + // .andWhere(checkChildConditions) + // .andWhere(typeCondition) + // .andWhere(revisionCondition); + + if (body.keyword != null && body.keyword != "") { + query.orWhere( new Brackets((qb) => { qb.andWhere( body.keyword != null && body.keyword != "" @@ -2315,36 +2408,39 @@ export class PositionController extends Controller { .andWhere(revisionCondition); }), ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ); + } + + let [posMaster, total] = await query .orderBy("orgRoot.orgRootOrder", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC") From a813d31df9c8488b78b00735677c40b88fd67cdf Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 15 Dec 2025 17:30:33 +0700 Subject: [PATCH 05/14] #2123 --- src/controllers/EmployeePositionController.ts | 169 ++++++++--------- .../EmployeeTempPositionController.ts | 170 +++++++++--------- src/controllers/PositionController.ts | 30 ++++ 3 files changed, 204 insertions(+), 165 deletions(-) diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 4a1566f6..4f679477 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -1021,12 +1021,12 @@ export class EmployeePositionController extends Controller { let typeCondition: any = {}; let checkChildConditions: any = {}; let keywordAsInt: any; - let searchShortName = ""; - let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName = "1=1"; + let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo)`; + let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo)`; + let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo)`; + let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo)`; + let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo)`; let _data = await new permission().PermissionOrgList(request, "SYS_ORG_EMP"); if (body.type === 0) { typeCondition = { @@ -1036,7 +1036,7 @@ export class EmployeePositionController extends Controller { checkChildConditions = { orgChild1Id: IsNull(), }; - searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 1) { @@ -1047,7 +1047,7 @@ export class EmployeePositionController extends Controller { checkChildConditions = { orgChild2Id: IsNull(), }; - searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 2) { @@ -1058,7 +1058,7 @@ export class EmployeePositionController extends Controller { checkChildConditions = { orgChild3Id: IsNull(), }; - searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 3) { @@ -1069,14 +1069,14 @@ export class EmployeePositionController extends Controller { checkChildConditions = { orgChild4Id: IsNull(), }; - searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 4) { typeCondition = { orgChild4Id: body.id, }; - searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } let findPosition: any; let masterId = new Array(); @@ -1126,7 +1126,7 @@ export class EmployeePositionController extends Controller { }, ]; - const [posMaster, total] = await AppDataSource.getRepository(EmployeePosMaster) + let query = AppDataSource.getRepository(EmployeePosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") @@ -1190,7 +1190,9 @@ export class EmployeePositionController extends Controller { child4: _data.child4, }, ) - .orWhere( + + if (body.keyword != null && body.keyword != "") { + query.orWhere( new Brackets((qb) => { qb.andWhere( body.keyword != null && body.keyword != "" @@ -1204,51 +1206,54 @@ export class EmployeePositionController extends Controller { .andWhere(revisionCondition); }), ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(posType.posTypeShortName,' ',posLevel.posLevelName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(posType.posTypeShortName,' ',posLevel.posLevelName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + } + + let [posMaster, total] = await query .orderBy("orgRoot.orgRootOrder", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC") @@ -1661,50 +1666,50 @@ export class EmployeePositionController extends Controller { const type0LastPosMasterNo = requestBody.type == 0 ? await this.employeePosMasterRepository.find({ - where: { - orgRootId: requestBody.id, - orgChild1Id: IsNull(), - }, - }) + where: { + orgRootId: requestBody.id, + orgChild1Id: IsNull(), + }, + }) : []; const type1LastPosMasterNo = requestBody.type == 1 ? await this.employeePosMasterRepository.find({ - where: { - orgChild1Id: requestBody.id, - orgChild2Id: IsNull(), - }, - }) + where: { + orgChild1Id: requestBody.id, + orgChild2Id: IsNull(), + }, + }) : []; const type2LastPosMasterNo = requestBody.type == 2 ? await this.employeePosMasterRepository.find({ - where: { - orgChild2Id: requestBody.id, - orgChild3Id: IsNull(), - }, - }) + where: { + orgChild2Id: requestBody.id, + orgChild3Id: IsNull(), + }, + }) : []; const type3LastPosMasterNo = requestBody.type == 3 ? await this.employeePosMasterRepository.find({ - where: { - orgChild3Id: requestBody.id, - orgChild4Id: IsNull(), - }, - }) + where: { + orgChild3Id: requestBody.id, + orgChild4Id: IsNull(), + }, + }) : []; const type4LastPosMasterNo = requestBody.type == 4 ? await this.employeePosMasterRepository.find({ - where: { - orgChild4Id: requestBody.id, - }, - }) + where: { + orgChild4Id: requestBody.id, + }, + }) : []; const allLastPosMasterNo = [ diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index 7ef5ff48..db110dce 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -769,12 +769,12 @@ export class EmployeeTempPositionController extends Controller { let typeCondition: any = {}; let checkChildConditions: any = {}; let keywordAsInt: any; - let searchShortName = ""; - let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; - let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; + let searchShortName = "1=1"; + let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo)`; + let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo)`; + let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo)`; + let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo)`; + let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo)`; let _data = await new permission().PermissionOrgList(request, "SYS_ORG_TEMP"); if (body.type === 0) { typeCondition = { @@ -784,7 +784,7 @@ export class EmployeeTempPositionController extends Controller { checkChildConditions = { orgChild1Id: IsNull(), }; - searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 1) { @@ -795,7 +795,7 @@ export class EmployeeTempPositionController extends Controller { checkChildConditions = { orgChild2Id: IsNull(), }; - searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 2) { @@ -806,7 +806,7 @@ export class EmployeeTempPositionController extends Controller { checkChildConditions = { orgChild3Id: IsNull(), }; - searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 3) { @@ -817,14 +817,14 @@ export class EmployeeTempPositionController extends Controller { checkChildConditions = { orgChild4Id: IsNull(), }; - searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } else { } } else if (body.type === 4) { typeCondition = { orgChild4Id: body.id, }; - searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; + searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`; } let findPosition: any; let masterId = new Array(); @@ -873,8 +873,7 @@ export class EmployeeTempPositionController extends Controller { : { posMasterNo: Like(`%${body.keyword}%`) })), }, ]; - - const [posMaster, total] = await AppDataSource.getRepository(EmployeeTempPosMaster) + let query = AppDataSource.getRepository(EmployeeTempPosMaster) .createQueryBuilder("posMaster") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1") @@ -938,7 +937,9 @@ export class EmployeeTempPositionController extends Controller { child4: _data.child4, }, ) - .orWhere( + + if (body.keyword != null && body.keyword != "") { + query.orWhere( new Brackets((qb) => { qb.andWhere( body.keyword != null && body.keyword != "" @@ -952,51 +953,54 @@ export class EmployeeTempPositionController extends Controller { .andWhere(revisionCondition); }), ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) - .orWhere( - new Brackets((qb) => { - qb.andWhere( - body.keyword != null && body.keyword != "" - ? `CONCAT(posType.posTypeShortName,' ',posLevel.posLevelName) like '%${body.keyword}%'` - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ) - .andWhere(checkChildConditions) - .andWhere(typeCondition) - .andWhere(revisionCondition); - }), - ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + .orWhere( + new Brackets((qb) => { + qb.andWhere( + body.keyword != null && body.keyword != "" + ? `CONCAT(posType.posTypeShortName,' ',posLevel.posLevelName) like '%${body.keyword}%'` + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) + .andWhere(checkChildConditions) + .andWhere(typeCondition) + .andWhere(revisionCondition); + }), + ) + } + + let [posMaster, total] = await query .orderBy("orgRoot.orgRootOrder", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC") @@ -1408,50 +1412,50 @@ export class EmployeeTempPositionController extends Controller { const type0LastPosMasterNo = requestBody.type == 0 ? await this.employeeTempPosMasterRepository.find({ - where: { - orgRootId: requestBody.id, - orgChild1Id: IsNull(), - }, - }) + where: { + orgRootId: requestBody.id, + orgChild1Id: IsNull(), + }, + }) : []; const type1LastPosMasterNo = requestBody.type == 1 ? await this.employeeTempPosMasterRepository.find({ - where: { - orgChild1Id: requestBody.id, - orgChild2Id: IsNull(), - }, - }) + where: { + orgChild1Id: requestBody.id, + orgChild2Id: IsNull(), + }, + }) : []; const type2LastPosMasterNo = requestBody.type == 2 ? await this.employeeTempPosMasterRepository.find({ - where: { - orgChild2Id: requestBody.id, - orgChild3Id: IsNull(), - }, - }) + where: { + orgChild2Id: requestBody.id, + orgChild3Id: IsNull(), + }, + }) : []; const type3LastPosMasterNo = requestBody.type == 3 ? await this.employeeTempPosMasterRepository.find({ - where: { - orgChild3Id: requestBody.id, - orgChild4Id: IsNull(), - }, - }) + where: { + orgChild3Id: requestBody.id, + orgChild4Id: IsNull(), + }, + }) : []; const type4LastPosMasterNo = requestBody.type == 4 ? await this.employeeTempPosMasterRepository.find({ - where: { - orgChild4Id: requestBody.id, - }, - }) + where: { + orgChild4Id: requestBody.id, + }, + }) : []; const allLastPosMasterNo = [ diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 4bfbb642..9050cac6 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -2389,6 +2389,36 @@ export class PositionController extends Controller { : "1=1", { child1: _data.child1 } ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `posMaster.orgChild2Id IN (:...child2)` + : `posMaster.orgChild2Id is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `posMaster.orgChild3Id IN (:...child3)` + : `posMaster.orgChild3Id is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `posMaster.orgChild4Id IN (:...child4)` + : `posMaster.orgChild4Id is null` + : "1=1", + { + child4: _data.child4, + }, + ) // .andWhere(checkChildConditions) // .andWhere(typeCondition) // .andWhere(revisionCondition); From 586331e87048f690668c8542cf29fc780ce5733c Mon Sep 17 00:00:00 2001 From: harid Date: Wed, 17 Dec 2025 12:37:05 +0700 Subject: [PATCH 06/14] =?UTF-8?q?API=20=E0=B8=95=E0=B8=A3=E0=B8=A7?= =?UTF-8?q?=E0=B8=88=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=8A=E0=B9=87?= =?UTF-8?q?=E0=B8=84=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3=E0=B8=95?= =?UTF-8?q?=E0=B8=B1=E0=B8=A7=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A=E0=B8=B2?= =?UTF-8?q?=E0=B8=8A=E0=B8=99=20=20=E0=B8=97=E0=B8=B3=E0=B9=84=E0=B8=A7?= =?UTF-8?q?=E0=B9=89=E0=B9=83=E0=B8=AB=E0=B9=89=20service=20=E0=B8=AD?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=99=E0=B9=86=20=E0=B8=A0=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B9=83=E0=B8=99=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A?= =?UTF-8?q?=20call=20=E0=B8=A1=E0=B8=B2=E0=B8=95=E0=B8=A3=E0=B8=A7?= =?UTF-8?q?=E0=B8=88=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=A5=E0=B8=82?= =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=88=E0=B8=B3=E0=B8=95=E0=B8=B1=E0=B8=A7=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=8A=E0=B8=B2=E0=B8=8A=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationDotnetController.ts | 17 +++++++++++++++++ src/interfaces/extension.ts | 16 +++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 00eb9b5a..ddac1c70 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -57,6 +57,23 @@ export class OrganizationDotnetController extends Controller { private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); + /** + * ทำไว้ให้ service อื่นๆ ภายในระบบ call มาตรวจสอบเลขบัตรประจำตัวประชาชน + * + * @summary API ตรวจสอบเช็คเลขบัตรประจำตัวประชาชน + * + */ + @Post("check-citizen") + public async CheckCitizen( + @Body() + body: { + citizenId: string; + }, + ) { + let citizen = Extension.CheckCitizen(body.citizenId) + return new HttpSuccess(citizen); + } + /** * 1. API Search Profile * diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 4a5dc5a3..24da5b93 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -251,8 +251,11 @@ class Extension { public static CheckCitizen(value: string) { let citizen = value; - if (citizen == null || citizen == "") { - return citizen; + if (citizen == null || citizen == "" || citizen == undefined) { + throw new HttpError( + HttpStatus.NOT_FOUND, + "กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชน", + ); } if (citizen.length !== 13) { throw new HttpError( @@ -277,9 +280,12 @@ class Extension { const calStp2 = cal % 11; const chkDigit = (11 - calStp2) % 10; - // if (citizenIdDigits[12] !== chkDigit) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง"); - // } + if (citizenIdDigits[12] !== chkDigit) { + throw new HttpError( + HttpStatus.NOT_FOUND, + "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง" + ); + } return citizen; } From fd22fcf990d6e0e8309a9a4a39303e7f7ac67029 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Dec 2025 17:29:18 +0700 Subject: [PATCH 07/14] log user --- src/middlewares/logs.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/middlewares/logs.ts b/src/middlewares/logs.ts index ce4802d2..70020810 100644 --- a/src/middlewares/logs.ts +++ b/src/middlewares/logs.ts @@ -76,6 +76,8 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) { if (req.url.startsWith("/api/v1/org/apiKey/")) system = "admin"; if (req.url.startsWith("/api/v1/org/api-manage/")) system = "admin"; + if (req.url.startsWith("/api/v1/org/keycloak/")) system = "registry"; + const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; const profileByKeycloak = await repoProfile.findOne({ where: { keycloak: req.app.locals.logData.userId }, From 2917d8b593d3cae8855ae8047202bad54b82eaca Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 18 Dec 2025 18:16:32 +0700 Subject: [PATCH 08/14] fix --- .../OrganizationDotnetController.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 00eb9b5a..dc8d0d6a 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -100,6 +100,27 @@ export class OrganizationDotnetController extends Controller { condition = "1=1"; break; } + } else if (body.role === "BROTHER") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 1: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 2: + condition = "orgChild1.ancestorDNA = :nodeId"; + break; + case 3: + condition = "orgChild2.ancestorDNA = :nodeId"; + break; + case 4: + condition = "orgChild3.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } conditionParams = { nodeId: body.nodeId }; } else if (body.role === "ROOT") { condition = "orgRoot.ancestorDNA = :nodeId"; From 18ae347122a6ecd853ecee890787ca561dda3901 Mon Sep 17 00:00:00 2001 From: Adisak Date: Thu, 18 Dec 2025 18:31:04 +0700 Subject: [PATCH 09/14] #2139 --- src/controllers/OrganizationDotnetController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 89fec9d1..443255c9 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -96,7 +96,7 @@ export class OrganizationDotnetController extends Controller { ) { let condition = "1=1"; let conditionParams = {}; - if (body.role === "CHILD" || body.role === "BROTHER") { + if (body.role === "CHILD") { switch (body.node) { case 0: condition = "orgRoot.ancestorDNA = :nodeId"; @@ -117,6 +117,7 @@ export class OrganizationDotnetController extends Controller { condition = "1=1"; break; } + conditionParams = { nodeId: body.nodeId }; } else if (body.role === "BROTHER") { switch (body.node) { case 0: From 4479507ae855fba07c1a4d784729012a568cc4cd Mon Sep 17 00:00:00 2001 From: Adisak Date: Fri, 19 Dec 2025 13:58:40 +0700 Subject: [PATCH 10/14] fix brother privilage --- .../OrganizationDotnetController.ts | 422 +++++++++--------- 1 file changed, 222 insertions(+), 200 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 443255c9..1a45751a 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -237,7 +237,7 @@ export class OrganizationDotnetController extends Controller { ) { let condition = "1=1"; let conditionParams = {}; - if (body.role === "CHILD" || body.role === "BROTHER") { + if (body.role === "CHILD") { switch (body.node) { case 0: condition = "orgRoot.ancestorDNA = :nodeId"; @@ -259,6 +259,28 @@ export class OrganizationDotnetController extends Controller { break; } conditionParams = { nodeId: body.nodeId }; + } else if (body.role === "BROTHER") { + switch (body.node) { + case 0: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 1: + condition = "orgRoot.ancestorDNA = :nodeId"; + break; + case 2: + condition = "orgChild1.ancestorDNA = :nodeId"; + break; + case 3: + condition = "orgChild2.ancestorDNA = :nodeId"; + break; + case 4: + condition = "orgChild3.ancestorDNA = :nodeId"; + break; + default: + condition = "1=1"; + break; + } + conditionParams = { nodeId: body.nodeId }; } else if (body.role === "ROOT") { condition = "orgRoot.ancestorDNA = :nodeId"; conditionParams = { nodeId: body.nodeId }; @@ -974,8 +996,8 @@ export class OrganizationDotnetController extends Controller { let positionLeaveName = profile.posType != null && - profile.posLevel != null && - (profile.posType.posTypeName == "บริหาร" || profile.posType.posTypeName == "อำนวยการ") + profile.posLevel != null && + (profile.posType.posTypeName == "บริหาร" || profile.posType.posTypeName == "อำนวยการ") ? `${profile.posType?.posTypeName ?? ""}${profile.posLevel?.posLevelName ?? ""}` : profile.posLevel?.posLevelName ?? null; const _profileCurrent = profile?.current_holders?.find( @@ -2567,26 +2589,26 @@ export class OrganizationDotnetController extends Controller { profile.current_holders.length == 0 ? null : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; @@ -2866,26 +2888,26 @@ export class OrganizationDotnetController extends Controller { profile.current_holders.length == 0 ? null : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; return { @@ -3081,26 +3103,26 @@ export class OrganizationDotnetController extends Controller { profile.current_holders.length == 0 ? null : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; return { @@ -3337,7 +3359,7 @@ export class OrganizationDotnetController extends Controller { const root = profile.current_holders == null || - profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot == null ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot; @@ -3397,41 +3419,41 @@ export class OrganizationDotnetController extends Controller { const posMaster = profile.current_holders == null || - profile.current_holders.length == 0 || - profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id) == 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 + 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 == + 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 == + 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 == + 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 == + profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 == null ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4; @@ -3570,30 +3592,30 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot - ?.orgRootName; + ?.orgRootName; const shortName = item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; @@ -3698,30 +3720,30 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot - ?.orgRootName; + ?.orgRootName; const shortName = item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; @@ -3905,25 +3927,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -4084,25 +4106,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName}${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -4254,25 +4276,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -4644,25 +4666,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -4810,25 +4832,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -4964,25 +4986,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -5248,25 +5270,25 @@ export class OrganizationDotnetController extends Controller { item.current_holders.length == 0 ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != - null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 != + null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild3 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild3 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild2 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild2 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgChild1 != null + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgChild1 != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != - null && - item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) - ?.orgRoot != null + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision?.id) + ?.orgRoot != null ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}` : null; const Oc = @@ -5547,16 +5569,16 @@ export class OrganizationDotnetController extends Controller { currentAddress: profile && profile.currentAddress ? profile.currentAddress + - (profile.currentSubDistrict && profile.currentSubDistrict.name - ? " ตำบล/แขวง " + profile.currentSubDistrict.name - : "") + - (profile.currentDistrict && profile.currentDistrict.name - ? " อำเภอ/เขต " + profile.currentDistrict.name - : "") + - (profile.currentProvince && profile.currentProvince.name - ? " จังหวัด " + profile.currentProvince.name - : "") + - profile.currentZipCode + (profile.currentSubDistrict && profile.currentSubDistrict.name + ? " ตำบล/แขวง " + profile.currentSubDistrict.name + : "") + + (profile.currentDistrict && profile.currentDistrict.name + ? " อำเภอ/เขต " + profile.currentDistrict.name + : "") + + (profile.currentProvince && profile.currentProvince.name + ? " จังหวัด " + profile.currentProvince.name + : "") + + profile.currentZipCode : "-", oc: oc ?? "-", root: @@ -5592,26 +5614,26 @@ export class OrganizationDotnetController extends Controller { positions: _position && _position.length > 0 ? _position.slice(0, -1).map((x: any, idx: number) => ({ - positionName: x.positionName, - dateStart: x.commandDateAffect ?? null, - dateEnd: _position[idx + 1]?.commandDateAffect ?? null, - positionType: x.positionType, - positionLevel: x.positionLevel, - orgRoot: x.orgRoot, - orgChild1: x.orgChild1, - orgChild2: x.orgChild2, - orgChild3: x.orgChild3, - orgChild4: x.orgChild4, - })) + positionName: x.positionName, + dateStart: x.commandDateAffect ?? null, + dateEnd: _position[idx + 1]?.commandDateAffect ?? null, + positionType: x.positionType, + positionLevel: x.positionLevel, + orgRoot: x.orgRoot, + orgChild1: x.orgChild1, + orgChild2: x.orgChild2, + orgChild3: x.orgChild3, + orgChild4: x.orgChild4, + })) : [], educations: profile.profileEducations && profile.profileEducations.length > 0 ? profile.profileEducations.map((x) => ({ - educationLevel: x.educationLevel, - institute: x.institute ?? "-", - country: x.country ?? "-", - finishDate: x.finishDate, - })) + educationLevel: x.educationLevel, + institute: x.institute ?? "-", + country: x.country ?? "-", + finishDate: x.finishDate, + })) : [], }; return new HttpSuccess(mapEmpProfile); @@ -5661,16 +5683,16 @@ export class OrganizationDotnetController extends Controller { currentAddress: profile && profile.currentAddress ? profile.currentAddress + - (profile.currentSubDistrict && profile.currentSubDistrict.name - ? " ตำบล/แขวง " + profile.currentSubDistrict.name - : "") + - (profile.currentDistrict && profile.currentDistrict.name - ? " อำเภอ/เขต " + profile.currentDistrict.name - : "") + - (profile.currentProvince && profile.currentProvince.name - ? " จังหวัด " + profile.currentProvince.name - : "") + - profile.currentZipCode + (profile.currentSubDistrict && profile.currentSubDistrict.name + ? " ตำบล/แขวง " + profile.currentSubDistrict.name + : "") + + (profile.currentDistrict && profile.currentDistrict.name + ? " อำเภอ/เขต " + profile.currentDistrict.name + : "") + + (profile.currentProvince && profile.currentProvince.name + ? " จังหวัด " + profile.currentProvince.name + : "") + + profile.currentZipCode : "-", oc: oc ?? "-", root: @@ -5706,26 +5728,26 @@ export class OrganizationDotnetController extends Controller { positions: _position && _position.length > 0 ? _position.slice(0, -1).map((x: any, idx: number) => ({ - positionName: x.positionName, - dateStart: x.commandDateAffect ?? null, - dateEnd: _position[idx + 1]?.commandDateAffect ?? null, - positionType: x.positionType, - positionLevel: x.positionLevel, - orgRoot: x.orgRoot, - orgChild1: x.orgChild1, - orgChild2: x.orgChild2, - orgChild3: x.orgChild3, - orgChild4: x.orgChild4, - })) + positionName: x.positionName, + dateStart: x.commandDateAffect ?? null, + dateEnd: _position[idx + 1]?.commandDateAffect ?? null, + positionType: x.positionType, + positionLevel: x.positionLevel, + orgRoot: x.orgRoot, + orgChild1: x.orgChild1, + orgChild2: x.orgChild2, + orgChild3: x.orgChild3, + orgChild4: x.orgChild4, + })) : [], educations: profile.profileEducations && profile.profileEducations.length > 0 ? profile.profileEducations.map((x) => ({ - educationLevel: x.educationLevel, - institute: x.institute ?? "-", - country: x.country ?? "-", - finishDate: x.finishDate, - })) + educationLevel: x.educationLevel, + institute: x.institute ?? "-", + country: x.country ?? "-", + finishDate: x.finishDate, + })) : [], }; return new HttpSuccess(mapProfile); From a96384130633c0aa192de082c5e2aa9f8113bd7a Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 22 Dec 2025 16:26:29 +0700 Subject: [PATCH 11/14] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=A2=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=99=E0=B8=AD=E0=B8=B8=E0=B8=98=E0=B8=A3=E0=B8=93=E0=B9=8C?= =?UTF-8?q?/=E0=B8=A3=E0=B9=89=E0=B8=AD=E0=B8=87=E0=B8=97=E0=B8=B8?= =?UTF-8?q?=E0=B8=81=E0=B8=82=E0=B9=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 36 ++++++++++++++++---- src/controllers/ProfileEmployeeController.ts | 31 +++++++++++++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index ac19ffdf..4dfa06fc 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -10800,14 +10800,27 @@ export class ProfileController extends Controller { */ @Post("search-personal-no-keycloak") async getProfileBySearchKeywordNoKeyCloak( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Body() body: { fieldName: string; keyword?: string; + system?: string; }, ) { + // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ + let _system: string = "SYS_REGISTRY_OFFICER"; + if (body.system) _system = body.system; + let _data = await new permission().PermissionOrgList(request, _system); + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + let findProfile: any; let total: any; const skip = (page - 1) * pageSize; @@ -10825,6 +10838,22 @@ export class ProfileController extends Controller { }); break; + case "fullName": + [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .where("profile.keycloak IS NULL") + .andWhere( + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` } + ) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + case "firstname": [findProfile, total] = await this.profileRepo.findAndCount({ where: { @@ -10861,13 +10890,6 @@ export class ProfileController extends Controller { break; } - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); - if (!findRevision) { - throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); - } - const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index f72df407..e2a1fc09 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5726,8 +5726,16 @@ export class ProfileEmployeeController extends Controller { body: { fieldName: string; keyword?: string; + system?: string; }, ) { + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + let findProfile: any; let total: any; const skip = (page - 1) * pageSize; @@ -5746,6 +5754,22 @@ export class ProfileEmployeeController extends Controller { }); break; + case "fullName": + [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .where("profile.keycloak IS NULL") + .andWhere( + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", + { keyword: `%${body.keyword}%` } + ) + .skip(skip) + .take(take) + .getManyAndCount(); + break; + case "firstname": [findProfile, total] = await this.profileRepo.findAndCount({ where: { @@ -5785,13 +5809,6 @@ export class ProfileEmployeeController extends Controller { break; } - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); - if (!findRevision) { - throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); - } - const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; From 0caec00c75ae030c45588761245ca3dc0d2253aa Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 22 Dec 2025 17:05:54 +0700 Subject: [PATCH 12/14] fix --- .../OrganizationDotnetController.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 1a45751a..74e60a10 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -4461,7 +4461,7 @@ export class OrganizationDotnetController extends Controller { ) { let typeCondition: any = {}; if (body.role === "CHILD" || body.role === "PARENT" || body.role === "BROTHER") { - if (body.role === "CHILD" || body.role === "BROTHER") { + if (body.role === "CHILD") { switch (body.node) { case 0: typeCondition = { @@ -4502,6 +4502,47 @@ export class OrganizationDotnetController extends Controller { typeCondition = {}; break; } + } else if (body.role === "BROTHER") { + switch (body.node) { + case 0: + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 1: + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 2: + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 3: + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 4: + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId, + }, + }; + break; + default: + typeCondition = {}; + break; + } } else if (body.role === "PARENT") { typeCondition = { orgRoot: { From f605f59b6e91a56074b1e180ec509073b17c7063 Mon Sep 17 00:00:00 2001 From: Adisak Date: Mon, 22 Dec 2025 17:14:56 +0700 Subject: [PATCH 13/14] #2146 --- .../OrganizationDotnetController.ts | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 74e60a10..0f47fff5 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -5106,7 +5106,7 @@ export class OrganizationDotnetController extends Controller { ) { let typeCondition: any = {}; if (body.role === "CHILD" || body.role === "PARENT" || body.role === "BROTHER") { - if (body.role === "CHILD" || body.role === "BROTHER") { + if (body.role === "CHILD") { switch (body.node) { case 0: typeCondition = { @@ -5147,6 +5147,47 @@ export class OrganizationDotnetController extends Controller { typeCondition = {}; break; } + } else if (body.role === "BROTHER") { + switch (body.node) { + case 0: + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 1: + typeCondition = { + orgRoot: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 2: + typeCondition = { + orgChild1: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 3: + typeCondition = { + orgChild2: { + ancestorDNA: body.nodeId, + }, + }; + break; + case 4: + typeCondition = { + orgChild3: { + ancestorDNA: body.nodeId, + }, + }; + break; + default: + typeCondition = {}; + break; + } } else if (body.role === "PARENT") { typeCondition = { orgRoot: { From 8083d9a0ae8ed81184e88b5a2d6e9cbc3d646443 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 23 Dec 2025 16:00:04 +0700 Subject: [PATCH 14/14] fix issue #1831, #2086, #2126, --- .../OrganizationDotnetController.ts | 20 +- .../OrganizationUnauthorizeController.ts | 10 +- src/controllers/ProfileController.ts | 180 ++++++++------- src/controllers/ProfileEmployeeController.ts | 214 +++++++++--------- 4 files changed, 225 insertions(+), 199 deletions(-) diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 0f47fff5..29a94f70 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -500,7 +500,7 @@ export class OrganizationDotnetController extends Controller { x.orgRevision?.orgRevisionIsCurrent == true, )?.orgChild4?.id ?? null, }; - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { orgRevision: { @@ -526,7 +526,7 @@ export class OrganizationDotnetController extends Controller { commanderId = pos.current_holder?.id; commanderKeycloak = pos.current_holder?.keycloak; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { orgRevision: { @@ -551,7 +551,7 @@ export class OrganizationDotnetController extends Controller { commanderId = pos.current_holder?.id; commanderKeycloak = pos.current_holder?.keycloak; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { orgRevision: { @@ -576,7 +576,7 @@ export class OrganizationDotnetController extends Controller { commanderId = pos.current_holder?.id; commanderKeycloak = pos.current_holder?.keycloak; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { orgRevision: { @@ -601,7 +601,7 @@ export class OrganizationDotnetController extends Controller { commanderId = pos.current_holder?.id; commanderKeycloak = pos.current_holder?.keycloak; } else { - let pos = await this.posMasterRepository.findOne({ + let pos = await this.empPosMasterRepository.findOne({ relations: ["current_holder"], where: { orgRevision: { @@ -2658,9 +2658,13 @@ export class OrganizationDotnetController extends Controller { posLevel: profile.posLevel?.posLevelName ?? "", posType: profile.posType?.posTypeName ?? "", profileSalary: profile.profileSalary, - profileInsignia: profile.profileInsignias.map((x) => { - return { ...x, insignia: x.insignia.name }; - }), + // profileInsignia: profile.profileInsignias.map((x) => { + // return { ...x, insignia: x.insignia.name }; + // }), + profileInsignia: profile.profileInsignias?.map((x) => ({ + ...x, + insignia: x.insignia?.name ?? null, + })) ?? [], amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, mouthSalaryAmount: profile.mouthSalaryAmount, diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index c72b600f..d63b885c 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -1664,9 +1664,13 @@ export class OrganizationUnauthorizeController extends Controller { posLevel: profile.posLevel?.posLevelName ?? "", posType: profile.posType?.posTypeName ?? "", profileSalary: profile.profileSalary, - profileInsignia: profile.profileInsignias.map((x) => { - return { ...x, insignia: x.insignia.name }; - }), + // profileInsignia: profile.profileInsignias.map((x) => { + // return { ...x, insignia: x.insignia.name }; + // }), + profileInsignia: profile.profileInsignias?.map((x) => ({ + ...x, + insignia: x.insignia?.name ?? null, + })) ?? [], amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, mouthSalaryAmount: profile.mouthSalaryAmount, diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 4dfa06fc..c4cf2eae 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -10821,114 +10821,124 @@ export class ProfileController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - let findProfile: any; - let total: any; - const skip = (page - 1) * pageSize; - const take = pageSize; + let queryLike = "1=1"; switch (body.fieldName) { case "citizenId": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - citizenId: Like(`%${body.keyword}%`), - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); + queryLike = "profile.citizenId LIKE :keyword"; break; case "fullName": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .leftJoinAndSelect("profile.current_holders", "current_holders") - .where("profile.keycloak IS NULL") - .andWhere( - "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", - { keyword: `%${body.keyword}%` } - ) - .skip(skip) - .take(take) - .getManyAndCount(); + queryLike = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; break; - case "firstname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - firstName: Like(`%${body.keyword}%`), - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); + case "firstName": + queryLike = "profile.firstName LIKE :keyword"; break; - case "lastname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - lastName: Like(`%${body.keyword}%`), - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); + case "lastName": + queryLike = "profile.lastName LIKE :keyword"; break; default: - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); + queryLike = "1=1"; break; } + let query = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .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") + .where("profile.keycloak IS NULL") + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ); + + const [findProfile, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; - const shortName = - item.current_holders.length == 0 - ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != - null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + let shortName = null; + let root = null; + let posMasterNo = null; + if (item.isLeave == false) { + shortName = + item.current_holders.length == 0 + ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgChild2 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != + null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgChild1 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != - null && + ?.orgChild2 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgRoot != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : null; - - const root = - item.current_holders.length == 0 || - (item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) - ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; - - const posMasterNo = item.current_holders?.find( - (x) => x.orgRevisionId == findRevision.id, - )?.posMasterNo; + ?.orgChild1 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; + root = + item.current_holders.length == 0 || + (item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) + ? null + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + root = root == null ? null : root.orgRootName; + posMasterNo = item.current_holders?.find( + (x) => x.orgRevisionId == findRevision.id, + )?.posMasterNo; + } + else { + const profileSalary = await this.salaryRepo + .createQueryBuilder("s") + .where("s.profileId = :profileId", { profileId: item.id }) + .andWhere("s.commandCode IN (:...codes)", { + codes: ["0","9","1","2","3","4","8","10","11","12","13","14","15","16"], + }) + .orderBy("s.order", "DESC") + .addOrderBy("s.createdAt", "DESC") + .take(2) + .getMany(); + if (profileSalary.length > 0) { + shortName = item.isRetirement + ? profileSalary.length > 1 + ? `${profileSalary[1]?.posNoAbb} ${profileSalary[1]?.posNo}` + : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}` + : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`; + posMasterNo = item.isRetirement + ? profileSalary.length > 1 + ? profileSalary[1]?.posNo + : profileSalary[0]?.posNo + : profileSalary[0]?.posNo; + root = item.isRetirement + ? profileSalary.length > 1 + ? profileSalary[1]?.orgRoot + : profileSalary[0]?.orgRoot + : profileSalary[0]?.orgRoot; + } + } const latestProfileEducation = await this.profileEducationRepo.findOne({ where: { profileId: item.id }, @@ -10952,7 +10962,7 @@ export class ProfileController extends Controller { positionType: item.posTypeId, positionTypeName: item.posType?.posTypeName, posNo: shortName, - organization: root == null ? null : root.orgRootName, + organization: root, salary: item.amount, posMasterNo: posMasterNo ?? null, posTypeId: item.posTypeId, diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e2a1fc09..d52bae77 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -5735,119 +5735,127 @@ export class ProfileEmployeeController extends Controller { if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } - - let findProfile: any; - let total: any; - const skip = (page - 1) * pageSize; - const take = pageSize; - switch (body.fieldName) { - case "citizenId": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - citizenId: Like(`%${body.keyword}%`), - employeeClass: "PERM", - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); - break; - - case "fullName": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .leftJoinAndSelect("profile.current_holders", "current_holders") - .where("profile.keycloak IS NULL") - .andWhere( - "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", - { keyword: `%${body.keyword}%` } - ) - .skip(skip) - .take(take) - .getManyAndCount(); - break; - - case "firstname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - firstName: Like(`%${body.keyword}%`), - employeeClass: "PERM", - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); - break; - - case "lastname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - lastName: Like(`%${body.keyword}%`), - employeeClass: "PERM", - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); - break; - - default: - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - keycloak: IsNull(), - employeeClass: "PERM", - }, - relations: ["posType", "posLevel", "current_holders"], - skip, - take, - }); - break; - } + + let queryLike = "1=1"; + switch (body.fieldName) { + case "citizenId": + queryLike = "profile.citizenId LIKE :keyword"; + break; + + case "fullName": + queryLike = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + break; + + case "firstName": + queryLike = "profile.firstName LIKE :keyword"; + break; + + case "lastName": + queryLike = "profile.lastName LIKE :keyword"; + break; + + default: + queryLike = "1=1"; + break; + } + + let query = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .leftJoinAndSelect("profile.current_holders", "current_holders") + .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") + .where("profile.keycloak IS NULL") + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ); + + const [findProfile, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; - const shortName = - item.current_holders.length == 0 - ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != - null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + let shortName = null; + let root = null; + let posMasterNo = null; + if (item.isLeave == false) { + shortName = + item.current_holders.length == 0 + ? null : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgChild2 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3 != + null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgChild1 != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != - null && + ?.orgChild2 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && item.current_holders.find((x) => x.orgRevisionId == findRevision.id) - ?.orgRoot != null - ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` - : null; + ?.orgChild1 != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != + null && + item.current_holders.find((x) => x.orgRevisionId == findRevision.id) + ?.orgRoot != null + ? `${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : null; - const root = - item.current_holders.length == 0 || - (item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) - ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; - - const posMasterNo = item.current_holders?.find( - (x) => x.orgRevisionId == findRevision.id, - )?.posMasterNo; + root = + item.current_holders.length == 0 || + (item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) + ? null + : item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + root = root == null ? null : root.orgRootName; + posMasterNo = item.current_holders?.find( + (x) => x.orgRevisionId == findRevision.id, + )?.posMasterNo; + } + else { + const profileSalary = await this.salaryRepo + .createQueryBuilder("s") + .where("s.profileEmployeeId = :profileId", { profileId: item.id }) + .andWhere("s.commandCode IN (:...codes)", { + codes: ["0","9","1","2","3","4","8","10","11","12","13","14","15","16"], + }) + .orderBy("s.order", "DESC") + .addOrderBy("s.createdAt", "DESC") + .take(2) + .getMany(); + if (profileSalary.length > 0) { + shortName = item.isRetirement + ? profileSalary.length > 1 + ? `${profileSalary[1]?.posNoAbb} ${profileSalary[1]?.posNo}` + : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}` + : `${profileSalary[0]?.posNoAbb} ${profileSalary[0]?.posNo}`; + posMasterNo = item.isRetirement + ? profileSalary.length > 1 + ? profileSalary[1]?.posNo + : profileSalary[0]?.posNo + : profileSalary[0]?.posNo; + root = item.isRetirement + ? profileSalary.length > 1 + ? profileSalary[1]?.orgRoot + : profileSalary[0]?.orgRoot + : profileSalary[0]?.orgRoot; + } + } + const latestProfileEducation = await this.profileEducationRepo.findOne({ where: { profileEmployeeId: item.id }, @@ -5871,7 +5879,7 @@ export class ProfileEmployeeController extends Controller { positionType: item.posTypeId, positionTypeName: item.posType?.posTypeName, posNo: shortName, - organization: root == null ? null : root.orgRootName, + organization: root, salary: item.amount, posMasterNo: posMasterNo ?? null, posTypeId: item.posTypeId,