fix test edit

This commit is contained in:
AdisakKanthawilang 2024-04-26 11:04:15 +07:00
parent 45c9ed549e
commit 19e1b55aee

View file

@ -774,10 +774,58 @@ export class PositionController extends Controller {
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
posMaster.reason = requestBody.reason == null ? "" : requestBody.reason;
if (posMaster.orgChild4Id != null) {
let orgRoot: any = null;
let SName: any = null;
if (requestBody.orgRootId != null)
orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId },
});
if (!orgRoot) {
let orgChild1: any = null;
if (requestBody.orgChild1Id != null)
orgChild1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id },
});
if (!orgChild1) {
let orgChild2: any = null;
if (requestBody.orgChild2Id != null)
orgChild2 = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id },
});
if (!orgChild2) {
let orgChild3: any = null;
if (requestBody.orgChild3Id != null)
orgChild3 = await this.child3Repository.findOne({
where: { id: requestBody.orgChild3Id },
});
if (!orgChild3) {
let orgChild4: any = null;
if (requestBody.orgChild4Id != null)
orgChild4 = await this.child4Repository.findOne({
where: { id: requestBody.orgChild4Id },
});
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
} else {
SName = orgChild4.orgChild4ShortName;
}
} else {
SName = orgChild3.orgChild3ShortName;
}
} else {
SName = orgChild2.orgChild2ShortName;
}
} else {
SName = orgChild1.orgChild1ShortName;
}
} else {
SName = orgRoot.orgRootShortName;
}
// if (posMaster.orgChild4Id != null) {
const chk_SName4 = await this.posMasterRepository.findOne({
where: {
orgChild4Id: posMaster.orgChild4Id,
orgChild4: { orgChild4ShortName: SName },
posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id),
},
@ -785,13 +833,13 @@ export class PositionController extends Controller {
if (chk_SName4 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
"ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้",
);
}
} else if (posMaster.orgChild3Id != null) {
// } else if (posMaster.orgChild3Id != null) {
const chk_SName3 = await this.posMasterRepository.findOne({
where: {
orgChild3Id: posMaster.orgChild3Id,
orgChild3: { orgChild3ShortName: SName },
posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id),
},
@ -799,13 +847,13 @@ export class PositionController extends Controller {
if (chk_SName3 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
"ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้",
);
}
} else if (posMaster.orgChild2Id != null) {
// } else if (posMaster.orgChild2Id != null) {
const chk_SName2 = await this.posMasterRepository.findOne({
where: {
orgChild2Id: posMaster.orgChild2Id,
orgChild2: { orgChild2ShortName: SName },
posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id),
},
@ -813,13 +861,13 @@ export class PositionController extends Controller {
if (chk_SName2 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
"ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้",
);
}
} else if (posMaster.orgChild1Id != null) {
// } else if (posMaster.orgChild1Id != null) {
const chk_SName1 = await this.posMasterRepository.findOne({
where: {
orgChild1Id: posMaster.orgChild1Id,
orgChild1: { orgChild1ShortName: SName },
posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id),
},
@ -827,13 +875,13 @@ export class PositionController extends Controller {
if (chk_SName1 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
"ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้",
);
}
} else if (posMaster.orgRootId != null) {
// } else if (posMaster.orgRootId != null) {
const chk_SName0 = await this.posMasterRepository.findOne({
where: {
orgRootId: posMaster.orgRootId,
orgRoot: { orgRootShortName: SName },
posMasterNo: requestBody.posMasterNo,
id: Not(posMaster.id),
},
@ -841,10 +889,10 @@ export class PositionController extends Controller {
if (chk_SName0 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
"ไม่สามารถแก้ไขชื่อตำแหน่งซ้ำกับข้อมูลที่มีอยู่แล้วได้",
);
}
}
// }
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;