From e63799eb00e09fbfcc4e895996866726c12c6737 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 29 Sep 2025 15:01:01 +0700 Subject: [PATCH] no message --- src/controllers/CommandController.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a9feeeb0..6a4a2e3f 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3023,15 +3023,24 @@ export class CommandController extends Controller { @Request() req: RequestWithUser, @Body() body: { - commandId: string[]; + resignId: string[]; }, ) { - const commands = await this.commandRepository.find({ where: { id: In(body.commandId) } }); - const data = commands.map((_data) => ({ - ..._data, - status: "CANCEL", - })); - await this.commandRepository.save(data); + const _refId = Array.from(new Set(body.resignId)); + // 1. ดึง commandRecive ที่ refId ตรงกับ resignId + const commandRecives = await this.commandReciveRepository.find({ + select: ["commandId"], + where: { refId: In(_refId) }, + }); + // 2. ดึง commandId ที่ไม่ซ้ำ + const commandIds = Array.from(new Set(commandRecives.map(x => x.commandId).filter(Boolean))); + // 3. อัปเดต status ของ command + if (commandIds.length > 0) { + await this.commandRepository.update( + { id: In(commandIds) }, + { status: "CANCEL" } + ); + } return new HttpSuccess(); }