diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 72c72ba9..87d5f4e6 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -19,7 +19,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Command } from "../entities/Command"; -import { Brackets, LessThan, MoreThan, Double } from "typeorm"; +import { Brackets, LessThan, MoreThan, Double, In } from "typeorm"; import { CommandType } from "../entities/CommandType"; import { CommandSend } from "../entities/CommandSend"; import { Profile } from "../entities/Profile"; @@ -111,7 +111,7 @@ export class CommandController extends Controller { : `${commandTypeId}`, }, ) - .orderBy("command.createdAt", "ASC") + .orderBy("command.createdAt", "DESC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -699,7 +699,10 @@ export class CommandController extends Controller { if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } - await this.commandSendCCRepository.delete({ commandSend: { commandId: command.id } }); + const commandSend = await this.commandSendRepository.find({ + where: { commandId: id }, + }); + 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 }); await this.commandRepository.delete(command.id);