feat: add notification
This commit is contained in:
parent
63aea8dc27
commit
11f4636342
1 changed files with 20 additions and 2 deletions
|
|
@ -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<boolean> {
|
|||
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<boolean> {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue