diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 7cc6c4b4..ab36300a 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -881,10 +881,24 @@ export class CommandController extends Controller { @Request() request: RequestWithUser, ) { await new permission().PermissionUpdate(request, "COMMAND"); - const command = await this.commandRepository.findOne({ where: { id: id } }); + const command = await this.commandRepository.findOne({ + where: { id: id }, + relations: ["commandType", "commandRecives"], + }); if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } + + const path = 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.commandReciveRepository.delete({ commandId: command.id }); command.status = "CANCEL"; command.lastUpdateUserId = request.user.sub; command.lastUpdateFullName = request.user.name;