From 0269036af7ac4404c6e40e3d08c0df8cd87403af Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 7 Oct 2024 22:35:43 +0700 Subject: [PATCH 1/3] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AD?= =?UTF-8?q?=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 74 ++++++++++++++++++---------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 842aff50..ac2a7246 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -432,13 +432,24 @@ export class CommandController extends Controller { * @param {string} id Id ผู้ได้รับคำสั่ง */ @Delete("tab2/{commandReciveId}") - async DeleteTab2(@Path() commandReciveId: string) { + async DeleteTab2(@Path() commandReciveId: string, @Request() request: RequestWithUser) { const commandRecive = await this.commandReciveRepository.findOne({ where: { id: commandReciveId }, + relations: ["command", "command.commandType"], }); if (!commandRecive) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง"); } + + const path = this.commandTypePath(commandRecive.command.commandType.code); + if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); + await new CallAPI() + .PostData(request, path + "/delete", { + refIds: [commandRecive.refId], + }) + .then(async (res) => {}) + .catch(() => {}); + const commandId = commandRecive.commandId; await this.commandReciveRepository.delete(commandRecive.id); @@ -452,6 +463,7 @@ export class CommandController extends Controller { p.order = i + 1; await this.commandReciveRepository.save(p); }); + return new HttpSuccess(); } @@ -619,7 +631,6 @@ export class CommandController extends Controller { if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง"); } - await this.commandSendCCRepository.delete({ commandSendId: commandSendId }); await this.commandSendRepository.delete(commandSendId); return new HttpSuccess(); @@ -725,9 +736,10 @@ export class CommandController extends Controller { * @param {string} id Id คำสั่ง */ @Delete("{id}") - async Delete(@Path() id: string) { + async Delete(@Path() id: string, @Request() request: RequestWithUser) { const command = await this.commandRepository.findOne({ where: { id: id }, + relations: ["commandType", "commandRecives"], }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); @@ -735,6 +747,16 @@ export class CommandController extends Controller { const commandSend = await this.commandSendRepository.find({ where: { commandId: id }, }); + + const path = this.commandTypePath(command.commandType.code); + if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); + await new CallAPI() + .PostData(request, path + "/delete", { + refIds: command.commandRecives.map((x) => x.refId), + }) + .then(async (res) => {}) + .catch(() => {}); + await this.commandSendCCRepository.delete({ commandSendId: In(commandSend.map((x) => x.id)) }); await this.commandReciveRepository.delete({ commandId: command.id }); await this.commandSendRepository.delete({ commandId: command.id }); @@ -979,20 +1001,22 @@ export class CommandController extends Controller { await new CallAPI() .PostData(request, path + "/attachment", { - refIds: command.commandRecives.map((x) => ({ - refId: x.refId, - Sequence: x.order, - CitizenId: x.citizenId, - Prefix: x.prefix, - FirstName: x.firstName, - LastName: x.lastName, - Amount: x.amount, - PositionSalaryAmount: x.positionSalaryAmount, - MouthSalaryAmount: x.mouthSalaryAmount, - RemarkHorizontal: x.remarkHorizontal, - RemarkVertical: x.remarkVertical, - CommandYear: command.commandYear, - })), + refIds: command.commandRecives + .filter((x) => x.refId != null) + .map((x) => ({ + refId: x.refId, + Sequence: x.order, + CitizenId: x.citizenId, + Prefix: x.prefix, + FirstName: x.firstName, + LastName: x.lastName, + Amount: x.amount, + PositionSalaryAmount: x.positionSalaryAmount, + MouthSalaryAmount: x.mouthSalaryAmount, + RemarkHorizontal: x.remarkHorizontal, + RemarkVertical: x.remarkVertical, + CommandYear: command.commandYear, + })), }) .then(async (res) => { console.log(res); @@ -1035,7 +1059,7 @@ export class CommandController extends Controller { ) { let command = new Command(); let commandCode = null; - let null_:any = null + let null_: any = null; if ( requestBody.commandId != undefined && requestBody.commandId != null && @@ -1074,13 +1098,13 @@ export class CommandController extends Controller { command.isAttachment = commandType.isAttachment; command.status = "NEW"; command.issue = commandType.name; - command.commandAffectDate = requestBody.commandAffectDate + (command.commandAffectDate = requestBody.commandAffectDate ? new Date(requestBody.commandAffectDate) - : null_, - command.commandExcecuteDate = requestBody.commandExcecuteDate - ? new Date(requestBody.commandExcecuteDate) - : null_, - command.createdUserId = request.user.sub; + : null_), + (command.commandExcecuteDate = requestBody.commandExcecuteDate + ? new Date(requestBody.commandExcecuteDate) + : null_), + (command.createdUserId = request.user.sub); command.createdFullName = request.user.name; command.createdAt = new Date(); command.lastUpdateUserId = request.user.sub; @@ -1093,7 +1117,7 @@ export class CommandController extends Controller { if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); await new CallAPI() .PostData(request, path, { - refIds: requestBody.persons.map((x) => x.refId), + refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId), }) .then(async (res) => { let order = From 3871ec5f9f4b6532eb4d3f7054d87d655f24e111 Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 7 Oct 2024 23:33:55 +0700 Subject: [PATCH 2/3] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=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\``); + } + +} From cb4fc6defb1e917bf2f5d850ef5e27b0a25b19fc Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 8 Oct 2024 10:09:56 +0700 Subject: [PATCH 3/3] =?UTF-8?q?fix=20search=20=E0=B8=AD=E0=B8=AD=E0=B8=81?= =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 6ddc0829..d8b3c62f 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -88,18 +88,6 @@ export class CommandController extends Controller { ) { const [commands, total] = await this.commandRepository .createQueryBuilder("command") - .andWhere( - new Brackets((qb) => { - qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { - keyword: `%${keyword}%`, - }).orWhere( - keyword != null && keyword != "" ? "command.createdFullName LIKE :keyword" : "1=1", - { - keyword: `%${keyword}%`, - }, - ); - }), - ) .andWhere( status != null && status != undefined && status != "" ? "command.status IN (:...status)" @@ -133,6 +121,18 @@ export class CommandController extends Controller { : `${commandTypeId}`, }, ) + .andWhere( + new Brackets((qb) => { + qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere( + keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", + { + keyword: `%${keyword}%`, + }, + ); + }), + ) .orderBy("command.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize)