แก้ออกคำสั่ง

This commit is contained in:
kittapath 2024-10-07 22:35:43 +07:00
parent 354d29e93b
commit 0269036af7

View file

@ -432,13 +432,24 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Delete("tab2/{commandReciveId}")
async DeleteTab2(@Path() commandReciveId: string) {
async DeleteTab2(@Path() commandReciveId: string, @Request() request: RequestWithUser) {
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
relations: ["command", "command.commandType"],
});
if (!commandRecive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง");
}
const path = this.commandTypePath(commandRecive.command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/delete", {
refIds: [commandRecive.refId],
})
.then(async (res) => {})
.catch(() => {});
const commandId = commandRecive.commandId;
await this.commandReciveRepository.delete(commandRecive.id);
@ -452,6 +463,7 @@ export class CommandController extends Controller {
p.order = i + 1;
await this.commandReciveRepository.save(p);
});
return new HttpSuccess();
}
@ -619,7 +631,6 @@ export class CommandController extends Controller {
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง");
}
await this.commandSendCCRepository.delete({ commandSendId: commandSendId });
await this.commandSendRepository.delete(commandSendId);
return new HttpSuccess();
@ -725,9 +736,10 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -735,6 +747,16 @@ export class CommandController extends Controller {
const commandSend = await this.commandSendRepository.find({
where: { commandId: id },
});
const path = this.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.commandSendCCRepository.delete({ commandSendId: In(commandSend.map((x) => x.id)) });
await this.commandReciveRepository.delete({ commandId: command.id });
await this.commandSendRepository.delete({ commandId: command.id });
@ -979,20 +1001,22 @@ export class CommandController extends Controller {
await new CallAPI()
.PostData(request, path + "/attachment", {
refIds: command.commandRecives.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
})
.then(async (res) => {
console.log(res);
@ -1035,7 +1059,7 @@ export class CommandController extends Controller {
) {
let command = new Command();
let commandCode = null;
let null_:any = null
let null_: any = null;
if (
requestBody.commandId != undefined &&
requestBody.commandId != null &&
@ -1074,13 +1098,13 @@ export class CommandController extends Controller {
command.isAttachment = commandType.isAttachment;
command.status = "NEW";
command.issue = commandType.name;
command.commandAffectDate = requestBody.commandAffectDate
(command.commandAffectDate = requestBody.commandAffectDate
? new Date(requestBody.commandAffectDate)
: null_,
command.commandExcecuteDate = requestBody.commandExcecuteDate
? new Date(requestBody.commandExcecuteDate)
: null_,
command.createdUserId = request.user.sub;
: null_),
(command.commandExcecuteDate = requestBody.commandExcecuteDate
? new Date(requestBody.commandExcecuteDate)
: null_),
(command.createdUserId = request.user.sub);
command.createdFullName = request.user.name;
command.createdAt = new Date();
command.lastUpdateUserId = request.user.sub;
@ -1093,7 +1117,7 @@ export class CommandController extends Controller {
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path, {
refIds: requestBody.persons.map((x) => x.refId),
refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId),
})
.then(async (res) => {
let order =