From 5ef5f7d4edd9f080288ac68efe4ab37f5109deeb Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 12 Mar 2026 14:53:45 +0700 Subject: [PATCH] fix bug #2183 --- src/controllers/CommandController.ts | 19 ++++++++++++------- src/services/CommandService.ts | 9 ++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 9ed83c08..7bbdb9ef 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -4040,10 +4040,12 @@ export class CommandController extends Controller { where: { refId: item.resignId }, relations: { command: true }, }); - const executeDate = commandResign ? new Date(commandResign.command.commandExcecuteDate).setHours(0,0,0,0) : today; - if (_command.status != "REPORTED" - && (_command.status != "WAITING" || today < executeDate)) { - await reOrderCommandRecivesAndDelete(commandResign!.refId); + const executeDate = commandResign + ? new Date(commandResign.command.commandExcecuteDate).setHours(0,0,0,0) + : today; + if (commandResign && _command.status !== "REPORTED" && + (_command.status !== "WAITING" || today < executeDate)) { + await reOrderCommandRecivesAndDelete(commandResign!.id); } } let _commandYear = item.commandYear; @@ -4377,6 +4379,7 @@ export class CommandController extends Controller { let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, + relations: { commandType: true }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -4438,9 +4441,11 @@ export class CommandController extends Controller { where: { refId: item.resignId }, relations: { command: true }, }); - const executeDate = commandResign ? new Date(commandResign.command.commandExcecuteDate).setHours(0,0,0,0) : today; - if (_command.status != "REPORTED" - && (_command.status !== "WAITING" || today < executeDate)) { + const executeDate = commandResign + ? new Date(commandResign.command.commandExcecuteDate).setHours(0,0,0,0) + : today; + if (commandResign && _command.status !== "REPORTED" && + (_command.status !== "WAITING" || today < executeDate)) { await reOrderCommandRecivesAndDelete(commandResign!.id); } } diff --git a/src/services/CommandService.ts b/src/services/CommandService.ts index ad9326b6..295d9ce8 100644 --- a/src/services/CommandService.ts +++ b/src/services/CommandService.ts @@ -4,20 +4,19 @@ import { Command } from "../entities/Command"; /** * เรียงลำดับผู้ได้รับคำสั่งใหม่หลังจากลบรายการ และอัพเดทสถานะคำสั่งถ้าไม่มีผู้ได้รับคำสั่งเหลือ - * @param refId refId ของผู้ได้รับคำสั่ง + * @param reciveId commandRecive.Id ของผู้ได้รับคำสั่ง * @param code ประเภทคำสั่ง * @returns Promise */ export async function reOrderCommandRecivesAndDelete( - refId: string + reciveId: string ): Promise { const commandReciveRepo = AppDataSource.getRepository(CommandRecive); const commandRepo = AppDataSource.getRepository(Command); - // ค้นหาข้อมูลผู้ได้รับคำสั่งตาม refId + // ค้นหาข้อมูลผู้ได้รับคำสั่งตาม reciveId const commandRecive = await commandReciveRepo.findOne({ - where: { refId: refId }, - relations: { command: true}, + where: { id: reciveId } }); if (commandRecive == null)