add rabbit noti
This commit is contained in:
parent
968d5f6dad
commit
2a9d00ada3
2 changed files with 83 additions and 124 deletions
|
|
@ -50,7 +50,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
|||
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
|
||||
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { sendToQueue } from "../services/rabbitmq";
|
||||
import { sendToQueue, sendToQueueCommandNoti } from "../services/rabbitmq";
|
||||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import {
|
||||
|
|
@ -1149,124 +1149,16 @@ export class CommandController extends Controller {
|
|||
}))
|
||||
: [];
|
||||
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles", {
|
||||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserIds: profiles,
|
||||
payload: "", //แนบไฟล์
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
let profilesSend =
|
||||
command && command.commandSends.length > 0
|
||||
? command.commandSends
|
||||
.filter((x) => x.profileId != null)
|
||||
.map((x) => ({
|
||||
receiverUserId: x.profileId,
|
||||
notiLink: "",
|
||||
isSendMail: x.commandSendCCs.map((x) => x.name == "EMAIL").length > 0 ? true : false,
|
||||
isSendInbox: x.commandSendCCs.map((x) => x.name == "INBOX").length > 0 ? true : false,
|
||||
isSendNotification: true,
|
||||
}))
|
||||
: [];
|
||||
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles-send", {
|
||||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserIds: profilesSend,
|
||||
payload: "", //แนบไฟล์
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
if (
|
||||
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
|
||||
new Date(
|
||||
command.commandExcecuteDate.getFullYear(),
|
||||
command.commandExcecuteDate.getMonth(),
|
||||
command.commandExcecuteDate.getDate(),
|
||||
)
|
||||
) {
|
||||
command.status = "WAITING";
|
||||
command.lastUpdateUserId = request.user.sub;
|
||||
command.lastUpdateFullName = request.user.name;
|
||||
command.lastUpdatedAt = new Date();
|
||||
await this.commandRepository.save(command);
|
||||
} else {
|
||||
const path = commandTypePath(command.commandType.code);
|
||||
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||
const msg = {
|
||||
data: {
|
||||
id: command.id,
|
||||
status: "REPORTED",
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
},
|
||||
user: request.user,
|
||||
token: request.headers["authorization"],
|
||||
};
|
||||
sendToQueue(msg);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ออกคำสั่ง
|
||||
*
|
||||
* @summary API ออกคำสั่ง
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Put("testRabbit/{id}")
|
||||
async testRabbit(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: { sign?: boolean },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "COMMAND");
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["commandType", "commandRecives"],
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
command.isSign = true;
|
||||
if (command.commandExcecuteDate == null)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
|
||||
|
||||
let profiles =
|
||||
command && command.commandRecives.length > 0
|
||||
? command.commandRecives
|
||||
.filter((x) => x.profileId != null)
|
||||
.map((x) => ({
|
||||
receiverUserId: x.profileId,
|
||||
notiLink: "",
|
||||
}))
|
||||
: [];
|
||||
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profiles", {
|
||||
subject: `${command.issue}`,
|
||||
body: `${command.issue}`,
|
||||
receiverUserIds: profiles,
|
||||
payload: "", //แนบไฟล์
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
|
||||
const msgNoti = {
|
||||
data: {
|
||||
command: command,
|
||||
profiles: profiles
|
||||
},
|
||||
user: request.user,
|
||||
token: request.headers["authorization"],
|
||||
};
|
||||
sendToQueueCommandNoti(msgNoti);
|
||||
|
||||
if (
|
||||
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
|
||||
new Date(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue