From b90e4114a83ab8ea504b956b71073805ba69e62f Mon Sep 17 00:00:00 2001 From: mamoss <> Date: Mon, 15 Sep 2025 16:24:07 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AB=E0=B8=B2=20=E0=B8=AA=E0=B8=81?= =?UTF-8?q?=E0=B8=811?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/OrganizationController.ts | 58 +++++++++++++++-------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 37663cc2..20511811 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -163,7 +163,7 @@ export class OrganizationController extends Controller { await sendToQueueOrgDraft(msg); return new HttpSuccess("Draft is being created... Processing in the background."); } catch (error: any) { - throw error; + throw error; } } @@ -3203,19 +3203,19 @@ export class OrganizationController extends Controller { try { // CheckQueueInProgress // console.log("🚀 ตรวจสอบว่ามีงานอยู่ในคิว"); - const [isBusyDraft, isBusyPublish] = await Promise.all([ - checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`), - checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`), - ]); - // console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft); - // console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish); - if (isBusyDraft || isBusyPublish) { - // console.log("🚫 พบว่ามีงานอยู่ในคิว — error") - throw new HttpError( - HttpStatusCode.CONFLICT, - "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", - ); - } + const [isBusyDraft, isBusyPublish] = await Promise.all([ + checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG_DRAFT}`), + checkQueueInProgress(`${process.env.AMQ_QUEUE_ORG}`), + ]); + // console.log("✅ ตรวจสอบแล้ว Draft Busy:", isBusyDraft); + // console.log("✅ ตรวจสอบแล้ว Publish Busy:", isBusyPublish); + if (isBusyDraft || isBusyPublish) { + // console.log("🚫 พบว่ามีงานอยู่ในคิว — error") + throw new HttpError( + HttpStatusCode.CONFLICT, + "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", + ); + } const today = new Date(); today.setHours(0, 0, 0, 0); // Set time to the beginning of the day @@ -3252,7 +3252,7 @@ export class OrganizationController extends Controller { await sendToQueueOrg(msg); return new HttpSuccess(); } catch (error: any) { - throw error; + throw error; } } @@ -7723,17 +7723,18 @@ export class OrganizationController extends Controller { where: { orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, orgRoot: { isCommission: true }, + orgChild1Id: IsNull(), isDirector: true, current_holderId: Not(IsNull()), - posMasterActs: { statusReport: "DONE" }, - posMasterActChilds: { statusReport: "DONE" }, + // posMasterActs: { statusReport: "DONE" }, + // posMasterActChilds: { statusReport: "DONE" }, }, order: { posMasterOrder: "ASC", posMasterActChilds: { posMasterOrder: "ASC" } }, relations: [ "current_holder", - "posMasterActChilds", - "posMasterActChilds.posMasterChild", - "posMasterActChilds.posMasterChild.current_holder", + // "posMasterActChilds", + // "posMasterActChilds.posMasterChild", + // "posMasterActChilds.posMasterChild.current_holder", ], }); if (posMaster.length <= 0) { @@ -7743,6 +7744,23 @@ export class OrganizationController extends Controller { }); } if (posMaster[0].current_holder == null) { + const posMaster = await this.posMasterRepository.find({ + where: { + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + orgRoot: { isCommission: true }, + orgChild1Id: IsNull(), + isDirector: true, + posMasterActs: { statusReport: "DONE" }, + posMasterActChilds: { statusReport: "DONE" }, + }, + order: { posMasterOrder: "ASC", posMasterActChilds: { posMasterOrder: "ASC" } }, + relations: [ + "current_holder", + "posMasterActChilds", + "posMasterActChilds.posMasterChild", + "posMasterActChilds.posMasterChild.current_holder", + ], + }); if ( posMaster[0].posMasterActChilds.length <= 0 || posMaster[0].posMasterActChilds[0].posMasterChild == null ||