From 11f4636342d6b49c80dff1baed05a6c2b130e5cc Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 31 Mar 2025 17:34:06 +0700 Subject: [PATCH] feat: add notification --- src/services/rabbitmq.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 45a95520..3bb45ef6 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -24,6 +24,7 @@ import { Position } from "../entities/Position"; import { In, Not } from "typeorm"; import { PosMasterAct } from "../entities/PosMasterAct"; import { PermissionOrg } from "../entities/PermissionOrg"; +import { sendWebSocket } from "./webSocket"; export let sendToQueue: (payload: any) => void; export let sendToQueueOrg: (payload: any) => void; @@ -122,6 +123,14 @@ async function handler(msg: amqp.ConsumeMessage): Promise { relations: ["commandType", "commandRecives"], }); if (!command) return true; + sendWebSocket( + "send-command-notification", + { + message: `ระบบทำการออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543}`, + payload: command, + }, + { userId: user.sub }, + ).catch(console.error); const path = commandTypePath(command.commandType.code); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); return await new CallAPI() @@ -156,8 +165,17 @@ async function handler(msg: amqp.ConsumeMessage): Promise { console.log("[AMQ] Excecute Command Success"); Object.assign(command, { status, lastUpdateUserId, lastUpdateFullName, lastUpdatedAt }); const result = await repo.save(command).catch((e) => console.log(e)); - if (result) return true; - return false; + + sendWebSocket( + "send-command-notification", + { + message: `ระบบออกคำสั่งเลขที่ ${command.commandNo}/${command.commandYear + 543} เสร็จสิ้น`, + payload: command, + }, + { userId: user.sub }, + ).catch(console.error); + + return !!result; }) .catch((e) => { console.error(e);