fix create position

This commit is contained in:
AdisakKanthawilang 2025-09-05 13:30:13 +07:00
parent 2f94ee747e
commit b222cbae3f

View file

@ -964,34 +964,40 @@ export class PositionController extends Controller {
let orgRoot: any = null; let orgRoot: any = null;
let SName: any = null; let SName: any = null;
let revisionId:any = null;
if (requestBody.orgRootId != null) if (requestBody.orgRootId != null)
orgRoot = await this.orgRootRepository.findOne({ orgRoot = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
revisionId = orgRoot.orgRevisionId;
if (!orgRoot) { if (!orgRoot) {
let orgChild1: any = null; let orgChild1: any = null;
if (requestBody.orgChild1Id != null) if (requestBody.orgChild1Id != null)
orgChild1 = await this.child1Repository.findOne({ orgChild1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id }, where: { id: requestBody.orgChild1Id },
}); });
revisionId = orgChild1.orgRevisionId;
if (!orgChild1) { if (!orgChild1) {
let orgChild2: any = null; let orgChild2: any = null;
if (requestBody.orgChild2Id != null) if (requestBody.orgChild2Id != null)
orgChild2 = await this.child2Repository.findOne({ orgChild2 = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id }, where: { id: requestBody.orgChild2Id },
}); });
revisionId = orgChild2.orgRevisionId;
if (!orgChild2) { if (!orgChild2) {
let orgChild3: any = null; let orgChild3: any = null;
if (requestBody.orgChild3Id != null) if (requestBody.orgChild3Id != null)
orgChild3 = await this.child3Repository.findOne({ orgChild3 = await this.child3Repository.findOne({
where: { id: requestBody.orgChild3Id }, where: { id: requestBody.orgChild3Id },
}); });
revisionId = orgChild3.orgRevisionId;
if (!orgChild3) { if (!orgChild3) {
let orgChild4: any = null; let orgChild4: any = null;
if (requestBody.orgChild4Id != null) if (requestBody.orgChild4Id != null)
orgChild4 = await this.child4Repository.findOne({ orgChild4 = await this.child4Repository.findOne({
where: { id: requestBody.orgChild4Id }, where: { id: requestBody.orgChild4Id },
}); });
revisionId = orgChild4.orgRevisionId;
if (!orgChild4) { if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
} else { } else {
@ -1169,9 +1175,12 @@ export class PositionController extends Controller {
); );
} }
const before = null; const before = null;
const chkRevision = await this.orgRevisionRepository.findOne({ let chkRevision:any = null;
where: { id: orgRoot.orgRevisionId }, if(revisionId){
}); chkRevision = await this.orgRevisionRepository.findOne({
where: { id: revisionId },
});
}
posMaster.createdUserId = request.user.sub; posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name; posMaster.createdFullName = request.user.name;
posMaster.lastUpdateUserId = request.user.sub; posMaster.lastUpdateUserId = request.user.sub;