diff --git a/src/app.ts b/src/app.ts index 221a0304..7965762c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -28,8 +28,8 @@ async function main() { origin: "*", }), ); - app.use(express.json()); - app.use(express.urlencoded({ extended: true })); + app.use(express.json({limit: "50mb"})); + app.use(express.urlencoded({ extended: true, limit: "50mb" })); app.use(logMiddleware); app.use("/", express.static("static")); app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index c37625f3..c2f2776c 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -162,6 +162,7 @@ export class OrganizationController extends Controller { request: request.user, revision: revision, }, + user: request.user, }; try { await sendToQueueOrgDraft(msg); diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 017dd6cd..7da207c2 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -394,7 +394,18 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { const child2Repository = AppDataSource.getRepository(OrgChild2); const child3Repository = AppDataSource.getRepository(OrgChild3); const child4Repository = AppDataSource.getRepository(OrgChild4); - + const { data, token, user } = JSON.parse(msg.content.toString()); + const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data; + if (user) { + sendWebSocket( + "send-publish-org", + { + success: true, + message: `ระบบกำลังทำการแพร่โครงสร้างหน่วยงาน`, + }, + { userId: user?.sub }, + ).catch(console.error); + } const orgRevisionPublish = await repoOrgRevision .createQueryBuilder("orgRevision") .where("orgRevision.orgRevisionIsDraft = false") @@ -418,9 +429,6 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { orgRevisionDraft.orgRevisionIsDraft = false; await repoOrgRevision.save(orgRevisionDraft); } - - const { data, token, user } = JSON.parse(msg.content.toString()); - const { id, status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt } = data; try { const posMaster = await repoPosmaster.find({ where: { orgRevisionId: id }, @@ -1400,9 +1408,29 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { } } console.log("[AMQ] Excecute Organization Success"); + if (user) { + sendWebSocket( + "send-publish-org", + { + success: true, + message: `ระบบทำการเผยแพร่โครงสร้างหน่วยงานเรียบร้อยแล้ว`, + }, + { userId: user?.sub }, + ).catch(console.error); + } return true; } catch (error) { console.error(error); + if (user) { + sendWebSocket( + "send-publish-org", + { + success: false, + message: `ระบบทำการเผยแพร่โครงสร้างหน่วยงานไม่สำเร็จ`, + }, + { userId: user?.sub }, + ).catch(console.error); + } return false; } } @@ -1424,7 +1452,16 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { const child2Repository = AppDataSource.getRepository(OrgChild2); const child3Repository = AppDataSource.getRepository(OrgChild3); const child4Repository = AppDataSource.getRepository(OrgChild4); - + if (user) { + sendWebSocket( + "send-publish-org", + { + success: true, + message: `ระบบกำลังทำการสร้างโครงสร้างหน่วยงาน`, + }, + { userId: user?.sub }, + ).catch(console.error); + } try { //cone tree if ( @@ -2097,9 +2134,29 @@ async function handler_org_draft(msg: amqp.ConsumeMessage): Promise { await orgRevisionRepository.remove(_orgRevisions); console.log("[AMQ] Create Draft Success"); + if (user) { + await sendWebSocket( + "send-create-draft-org", + { + success: true, + message: `ระบบทำการสร้างแบบร่างโครงสร้างหน่วยงานเรียบร้อยแล้ว`, + }, + { userId: user?.sub }, + ).catch(console.error); + } return true; } catch (error) { console.error(error); + if (user) { + await sendWebSocket( + "send-create-draft-org", + { + success: false, + message: `ระบบทำการสร้างแบบร่างโครงสร้างหน่วยงานไม่สำเร็จ`, + }, + { userId: user?.sub }, + ).catch(console.error); + } return false; } }