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\``); + } + +}