From 523991674c30c0df7a0bcd3ca981450bd55ffd4b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 6 Feb 2024 16:23:33 +0700 Subject: [PATCH] no message --- src/controllers/OrganizationController.ts | 18 ++++- src/controllers/PositionController.ts | 90 ++++++++++++----------- 2 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 2da5850a..33177b72 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -879,28 +879,35 @@ export class OrganizationController extends Controller { orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, totalPosition: await this.posMasterRepository.count({ - where: { orgChild3Id: orgChild3.id }, + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgChild3Id: orgChild3.id, + }, }), totalPositionCurrentUse: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild3Id: orgChild3.id, current_holderId: Not(IsNull()) || Not(""), }, }), totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild3Id: orgChild3.id, current_holderId: IsNull() || "", }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild3Id: orgChild3.id, next_holderId: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild3Id: orgChild3.id, next_holderId: IsNull() || "", }, @@ -926,10 +933,14 @@ export class OrganizationController extends Controller { orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, totalPosition: await this.posMasterRepository.count({ - where: { orgChild4Id: orgChild4.id }, + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgChild4Id: orgChild4.id, + }, }), totalPositionCurrentUse: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild4Id: orgChild4.id, current_holderId: Not(IsNull()) || Not(""), }, @@ -937,18 +948,21 @@ export class OrganizationController extends Controller { totalPositionCurrentVacant: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild4Id: orgChild4.id, current_holderId: IsNull() || "", }, }), totalPositionNextUse: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild4Id: orgChild4.id, next_holderId: Not(IsNull()) || Not(""), }, }), totalPositionNextVacant: await this.posMasterRepository.count({ where: { + orgRevisionId: orgRoot.orgRevisionId, orgChild4Id: orgChild4.id, next_holderId: IsNull() || "", }, diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 840a39f9..13929b56 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -653,44 +653,48 @@ export class PositionController extends Controller { } let findPosition: any; let masterId = new Array(); - const findTypes: PosType[] = await this.posTypeRepository.find({ - where: { posTypeName: Like(`%${body.keyword}%`) }, - select: ["id"], - }); - findPosition = await this.positionRepository.find({ - where: { posTypeId: In(findTypes.map((x) => x.id)) }, - select: ["posMasterId"], - }); - masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); - const findLevel: PosLevel[] = await this.posLevelRepository.find({ - where: { posLevelName: Like(`%${body.keyword}%`) }, - select: ["id"], - }); - findPosition = await this.positionRepository.find({ - where: { posLevelId: In(findLevel.map((x) => x.id)) }, - select: ["posMasterId"], - }); - masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); - const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({ - where: { posExecutiveName: Like(`%${body.keyword}%`) }, - select: ["id"], - }); - findPosition = await this.positionRepository.find({ - where: { posExecutiveId: In(findExecutive.map((x) => x.id)) }, - select: ["posMasterId"], - }); - masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); - findPosition = await this.positionRepository.find({ - where: { positionName: Like(`%${body.keyword}%`) }, - select: ["posMasterId"], - }); - masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); - let keywordAsInt: any; - keywordAsInt = body.keyword == null ? null : parseInt(body.keyword, 10); - if (isNaN(keywordAsInt)) { - keywordAsInt = "P@ssw0rd!z"; + if (body.keyword != null && body.keyword != "") { + const findTypes: PosType[] = await this.posTypeRepository.find({ + where: { posTypeName: Like(`%${body.keyword}%`) }, + select: ["id"], + }); + findPosition = await this.positionRepository.find({ + where: { posTypeId: In(findTypes.map((x) => x.id)) }, + select: ["posMasterId"], + }); + masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); + const findLevel: PosLevel[] = await this.posLevelRepository.find({ + where: { posLevelName: Like(`%${body.keyword}%`) }, + select: ["id"], + }); + findPosition = await this.positionRepository.find({ + where: { posLevelId: In(findLevel.map((x) => x.id)) }, + select: ["posMasterId"], + }); + masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); + const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({ + where: { posExecutiveName: Like(`%${body.keyword}%`) }, + select: ["id"], + }); + findPosition = await this.positionRepository.find({ + where: { posExecutiveId: In(findExecutive.map((x) => x.id)) }, + select: ["posMasterId"], + }); + masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); + findPosition = await this.positionRepository.find({ + where: { positionName: Like(`%${body.keyword}%`) }, + select: ["posMasterId"], + }); + masterId = masterId.concat(findPosition.map((position: any) => position.posMasterId)); + let keywordAsInt: any; + keywordAsInt = body.keyword == null ? null : parseInt(body.keyword, 10); + if (isNaN(keywordAsInt)) { + keywordAsInt = "P@ssw0rd!z"; + } + masterId = [...new Set(masterId)]; } - masterId = [...new Set(masterId)]; + console.log(masterId); + console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); const keywordConditions = [ // { @@ -700,13 +704,13 @@ export class PositionController extends Controller { { ...checkChildConditions, ...typeCondition, - id: In(masterId), - }, - { - ...checkChildConditions, - ...typeCondition, - posMasterNo: Like(`%${keywordAsInt}%`), + id: masterId.length > 0 ? In(masterId) : false, }, + // { + // ...checkChildConditions, + // ...typeCondition, + // posMasterNo: Like(`%${keywordAsInt}%`), + // }, ]; const [posMaster, total] = await this.posMasterRepository.findAndCount({