From bc86f4d2d98431056f04efb1fa30c64506145503 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 9 Feb 2024 22:55:42 +0700 Subject: [PATCH] no message --- src/controllers/OrganizationController.ts | 305 +++++++++++++--------- src/controllers/PositionController.ts | 7 +- src/controllers/ProfileController.ts | 8 + src/entities/PosDict.ts | 4 +- src/entities/Position.ts | 4 +- 5 files changed, 200 insertions(+), 128 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index b4761871..10269c11 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -753,46 +753,56 @@ export class OrganizationController extends Controller { }, }), totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : IsNull() || "", orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", }, }), totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : IsNull() || "", orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : IsNull() || "", orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: IsNull() || "", }, }), totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : IsNull() || "", orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : IsNull() || "", orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: IsNull() || "", }, }), @@ -849,46 +859,56 @@ export class OrganizationController extends Controller { }, }), totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", }, }), totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: IsNull() || "", }, }), totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : IsNull() || "", - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: IsNull() || "", }, }), @@ -948,46 +968,56 @@ export class OrganizationController extends Controller { }, }), totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", }, }), totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", current_holderId: IsNull() || "", }, }), totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : IsNull() || "", orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", next_holderId: IsNull() || "", }, }), @@ -1047,46 +1077,56 @@ export class OrganizationController extends Controller { }, }), totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "", }, }), totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "", current_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "", current_holderId: IsNull() || "", }, }), totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "", next_holderId: Not(IsNull()) || Not(""), }, }), totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "", next_holderId: IsNull() || "", }, }), @@ -1147,49 +1187,62 @@ export class OrganizationController extends Controller { }, }), totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : orgChild4.id, - }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : orgChild4.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : orgChild4.id, - current_holderId: IsNull() || "", + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, }, }), + totalRootPositionCurrentUse: + await this.posMasterRepository.count({ + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: Not(IsNull()) || Not(""), + }, + }), + totalRootPositionCurrentVacant: + await this.posMasterRepository.count({ + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + current_holderId: IsNull() || "", + }, + }), totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, + where: { + orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : orgChild4.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, next_holderId: Not(IsNull()) || Not(""), }, }), - totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id : orgChild1.id, orgChild2Id : orgChild2.id, - orgChild3Id : orgChild3.id, orgChild4Id : orgChild4.id, - next_holderId: IsNull() || "", - }, - }), + totalRootPositionNextVacant: + await this.posMasterRepository.count({ + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + next_holderId: IsNull() || "", + }, + }), })), ), })), @@ -1541,15 +1594,24 @@ export class OrganizationController extends Controller { orgRevisionDraft.orgRevisionIsCurrent = true; orgRevisionDraft.orgRevisionIsDraft = false; await this.orgRevisionRepository.save(orgRevisionDraft); + + const posMaster = await this.posMasterRepository.find({ + where: { orgRevisionId: orgRevisionDraft.id }, + }); + posMaster.forEach(async (item) => { + // if(item.next_holderId != null){ + item.current_holderId = item.next_holderId; + item.next_holderId = null; + await this.posMasterRepository.save(item); + // } + }); return new HttpSuccess(); } - /** * Cronjob */ async cronjobRevision() { - const today = new Date(); today.setHours(0, 0, 0, 0); // Set time to the beginning of the day const orgRevisionPublish = await this.orgRevisionRepository @@ -1571,7 +1633,6 @@ export class OrganizationController extends Controller { orgRevisionPublish.orgRevisionIsDraft = false; orgRevisionPublish.orgRevisionIsCurrent = false; await this.orgRevisionRepository.save(orgRevisionPublish); - } orgRevisionDraft.orgRevisionIsCurrent = true; orgRevisionDraft.orgRevisionIsDraft = false; @@ -1582,12 +1643,12 @@ export class OrganizationController extends Controller { }); posMaster.forEach(async (item) => { // if(item.next_holderId != null){ - item.current_holderId = item.next_holderId; - item.next_holderId = null; - await this.posMasterRepository.save(item); + item.current_holderId = item.next_holderId; + item.next_holderId = null; + await this.posMasterRepository.save(item); // } }); - + return new HttpSuccess(); } } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 1a013369..6b4b5453 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -426,7 +426,7 @@ export class PositionController extends Controller { requestBody: CreatePosMaster, @Request() request: { user: Record }, ) { - const posMaster = await this.posMasterRepository.findOne({ where: { id: id } }); + let posMaster = await this.posMasterRepository.findOne({ where: { id: id } }); if (!posMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } @@ -435,6 +435,9 @@ export class PositionController extends Controller { posMaster.orgChild2Id = null; posMaster.orgChild3Id = null; posMaster.orgChild4Id = null; + posMaster.posMasterNo = requestBody.posMasterNo; + posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix; + posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix; let orgRoot: any = null; if (requestBody.orgRootId != null) @@ -514,7 +517,7 @@ export class PositionController extends Controller { position.positionExecutiveField = x.posDictExecutiveField; position.positionArea = x.posDictArea; position.positionIsSelected = false; - position.posMasterId = posMaster.id; + position.posMasterId = posMaster?.id; position.createdUserId = request.user.sub; position.createdFullName = request.user.name; position.lastUpdateUserId = request.user.sub; diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index f91b3d7d..94fb4e53 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -330,6 +330,14 @@ export class ProfileController extends Controller { { keyword: `%${requestBody.keyword}%`, }, + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profile.citizenId LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, ); }), ) diff --git a/src/entities/PosDict.ts b/src/entities/PosDict.ts index f005d84a..bf236a09 100644 --- a/src/entities/PosDict.ts +++ b/src/entities/PosDict.ts @@ -88,10 +88,10 @@ export class CreatePosDict { posExecutiveId: string | null; @Column() - posDictExecutiveField: string; + posDictExecutiveField: string | null; @Column() - posDictArea: string; + posDictArea: string | null; } export type UpdatePosDict = Partial; diff --git a/src/entities/Position.ts b/src/entities/Position.ts index 90630067..268e8068 100644 --- a/src/entities/Position.ts +++ b/src/entities/Position.ts @@ -49,7 +49,7 @@ export class Position extends EntityBase { length: 255, default: null, }) - positionExecutiveField: string; + positionExecutiveField?: string; @Column({ nullable: true, @@ -57,7 +57,7 @@ export class Position extends EntityBase { length: 255, default: null, }) - positionArea: string; + positionArea?: string; @Column({ comment: "เป็นตำแหน่งที่ถูกเลือกในรอบนั้นๆ หรือไม่?",