From d4437c86403514b44a0556caec3c0a5bb14c6db6 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 18 Oct 2024 18:08:08 +0700 Subject: [PATCH] noti report --- src/controllers/CommandController.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index d4b19d46..26637b6a 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1004,7 +1004,7 @@ export class CommandController extends Controller { ) { const command = await this.commandRepository.findOne({ where: { id: id }, - relations: ["commandType", "commandRecives"], + relations: ["commandType", "commandRecives", "commandSends", "commandSends.commandSendCCs"], }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); @@ -1036,6 +1036,29 @@ export class CommandController extends Controller { .catch((error) => { console.error("Error calling API:", error); }); + let _profiles = + 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", { + subject: `${command.issue}`, + body: `${command.issue}`, + receiverUserIds: _profiles, + payload: "", //แนบไฟล์ + }) + .catch((error) => { + console.error("Error calling API:", error); + }); if ( new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) < new Date(