testRabbit
This commit is contained in:
parent
7e87cec833
commit
a130cc71a1
1 changed files with 82 additions and 0 deletions
|
|
@ -1127,6 +1127,88 @@ export class CommandController extends Controller {
|
||||||
return new HttpSuccess();
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
async cronjobCommand(@Request() request?: RequestWithUser) {
|
async cronjobCommand(@Request() request?: RequestWithUser) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
today.setUTCHours(0, 0, 0, 0);
|
today.setUTCHours(0, 0, 0, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue