delete command

This commit is contained in:
kittapath 2025-01-29 16:30:17 +07:00
parent 7a0ab2271d
commit a7c65df5e0

View file

@ -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;