From 3871ec5f9f4b6532eb4d3f7054d87d655f24e111 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 7 Oct 2024 23:33:55 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20noti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 19 +++++++++++++++++++ src/entities/CommandRecive.ts | 12 +++++++----- .../1728318691161-add_table_assign1.ts | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/migration/1728318691161-add_table_assign1.ts diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index ac2a7246..6ddc0829 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -895,6 +895,24 @@ export class CommandController extends Controller { command.isSign = true; if (command.commandExcecuteDate == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล"); + + let profiles = command.commandRecives + .filter((x) => x.profileId != null) + .map(async (x) => x.profileId); + + await new CallAPI() + .PostData(request, "/placement/noti/profiles", { + subject: `${command.issue}`, + body: `${command.issue}`, + receiverUserId: profiles, + payload: "",//แนบไฟล์ + isSendMail: true, + isSendInbox: true, + receiveDate: command.commandExcecuteDate, + }) + .catch((error) => { + console.error("Error calling API:", error); + }); if ( new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) < new Date( @@ -1049,6 +1067,7 @@ export class CommandController extends Controller { commandExcecuteDate?: Date | null; persons: { refId: string; + profileId?: string|null; citizenId: string; prefix: string; firstName: string; diff --git a/src/entities/CommandRecive.ts b/src/entities/CommandRecive.ts index 3b25ad3d..d719b6bd 100644 --- a/src/entities/CommandRecive.ts +++ b/src/entities/CommandRecive.ts @@ -101,11 +101,13 @@ export class CommandRecive extends EntityBase { @JoinColumn({ name: "commandId" }) command: Command; - // @Column({ - // length: 40, - // comment: "คีย์นอก(FK)ของตาราง profile", - // }) - // profileId: string; + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + default: null, + }) + profileId: string; // @ManyToOne(() => Profile, (profile) => profile.commandRecives) // @JoinColumn({ name: "profileId" }) diff --git a/src/migration/1728318691161-add_table_assign1.ts b/src/migration/1728318691161-add_table_assign1.ts new file mode 100644 index 00000000..73703727 --- /dev/null +++ b/src/migration/1728318691161-add_table_assign1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableAssign11728318691161 implements MigrationInterface { + name = 'AddTableAssign11728318691161' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`profileId\``); + } + +}