diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 69b31e58..86668e38 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -561,6 +561,27 @@ export function chunkArray(array: any, size: number) { return result; } +export async function PayloadSendNoti(commandId: string) { + if (!commandId) + return ""; + const commandRepository = AppDataSource.getRepository(Command); + const _command = await commandRepository.findOne({ + where: { + id: commandId, + }, + relations: ["commandType"], + }); + const _payload = { + name: _command && _command.commandType + ? `คำสั่ง${_command.commandType.name}` + : "", + url: `${process.env.API_URL}/salary/file/ระบบออกคำสั่ง/คำสั่ง/${commandId}/คำสั่ง`, + isReport: true, + isTemplate: false, + } + return JSON.stringify(_payload); +} + export function commandTypePath(commandCode: string): string | null { switch (commandCode) { case "C-PM-01": diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 8c19f8f7..d55667a6 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -24,6 +24,7 @@ import { PosMasterAct } from "../entities/PosMasterAct"; import { PermissionOrg } from "../entities/PermissionOrg"; import { sendWebSocket } from "./webSocket"; import { CreatePosMasterHistoryOfficer } from "./PositionService"; +import { PayloadSendNoti } from "../interfaces/utils"; export let sendToQueue: (payload: any) => void; export let sendToQueueOrg: (payload: any) => void; @@ -83,7 +84,7 @@ export async function init() { console.log("[AMQ] Listening for message..."); createConsumer(queue, channel, handler), //----> (3) Process Consumer - createConsumer(queue_org, channel, handler_org); + createConsumer(queue_org, channel, handler_org); createConsumer(queue_org_draft, channel, handler_org_draft); createConsumer(queue_command_noti, channel, handler_command_noti); // createConsumer(queue2, channel, handler2); @@ -445,6 +446,7 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise })) : []; + const payloadStr = await PayloadSendNoti(command.id); const profilesSendRequest = new CallAPI() .PostData( { headers: { authorization: token } }, @@ -453,7 +455,7 @@ async function handler_command_noti(msg: amqp.ConsumeMessage): Promise subject: `${command.issue}`, body: `${command.issue}`, receiverUserIds: profilesSend, - payload: "", // แนบไฟล์ (ถ้าจำเป็น) + payload: payloadStr, // แนบไฟล์ (ถ้าจำเป็น) }, false, )