diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index cd400837..37663cc2 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -124,20 +124,20 @@ export class OrganizationController extends Controller { @Request() request: RequestWithUser, ) { try { - // // CheckQueueInProgress - // 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, - // "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", - // ); - // } + // CheckQueueInProgress + 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, + "ไม่สามารถดำเนินการได้ หากกำลังเผยแพร่หรือสร้างแบบร่างโครงสร้างหน่วยงาน", + ); + } //new main revision const before = null; const revision = Object.assign(new OrgRevision(), requestBody) as OrgRevision; @@ -163,13 +163,7 @@ export class OrganizationController extends Controller { await sendToQueueOrgDraft(msg); return new HttpSuccess("Draft is being created... Processing in the background."); } catch (error: any) { - if (error?.status && error?.message) { - return error; - } - return new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "Failed to process the draft. Please try again later.", - ); + throw error; } } @@ -3209,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 @@ -3258,13 +3252,7 @@ export class OrganizationController extends Controller { await sendToQueueOrg(msg); return new HttpSuccess(); } catch (error: any) { - if (error?.status && error?.message) { - return error; - } - return new HttpError( - HttpStatusCode.INTERNAL_SERVER_ERROR, - "Failed to process the publish. Please try again later.", - ); + throw error; } }