แก้บัคย้ายตำแหน่ง
This commit is contained in:
parent
e16c5a9bef
commit
0746ad33ab
1 changed files with 245 additions and 154 deletions
|
|
@ -773,165 +773,237 @@ export class PositionController extends Controller {
|
||||||
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
|
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
|
||||||
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
|
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
|
||||||
posMaster.reason = requestBody.reason == null ? "" : requestBody.reason;
|
posMaster.reason = requestBody.reason == null ? "" : requestBody.reason;
|
||||||
posMaster.orgRootId = null;
|
// posMaster.orgRootId = null;
|
||||||
posMaster.orgChild1Id = null;
|
// posMaster.orgChild1Id = null;
|
||||||
posMaster.orgChild2Id = null;
|
// posMaster.orgChild2Id = null;
|
||||||
posMaster.orgChild3Id = null;
|
// posMaster.orgChild3Id = null;
|
||||||
posMaster.orgChild4Id = null;
|
// posMaster.orgChild4Id = null;
|
||||||
|
|
||||||
let orgRoot: any = null;
|
// let orgRoot: any = null;
|
||||||
let SName: any = null;
|
// let SName: 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 },
|
||||||
|
// });
|
||||||
|
// 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 {
|
||||||
|
// posMaster.orgRootId = orgChild4.orgRootId;
|
||||||
|
// posMaster.orgChild1Id = orgChild4.orgChild1Id;
|
||||||
|
// posMaster.orgChild2Id = orgChild4.orgChild2Id;
|
||||||
|
// posMaster.orgChild3Id = orgChild4.orgChild3Id;
|
||||||
|
// posMaster.orgChild4Id = orgChild4.id;
|
||||||
|
// posMaster.orgRevisionId = orgChild4.orgRevisionId;
|
||||||
|
// SName = orgChild4.orgChild4ShortName;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// posMaster.orgRootId = orgChild3.orgRootId;
|
||||||
|
// posMaster.orgChild1Id = orgChild3.orgChild1Id;
|
||||||
|
// posMaster.orgChild2Id = orgChild3.orgChild2Id;
|
||||||
|
// posMaster.orgChild3Id = orgChild3.id;
|
||||||
|
// posMaster.orgRevisionId = orgChild3.orgRevisionId;
|
||||||
|
// SName = orgChild3.orgChild3ShortName;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// posMaster.orgRootId = orgChild2.orgRootId;
|
||||||
|
// posMaster.orgChild1Id = orgChild2.orgChild1Id;
|
||||||
|
// posMaster.orgChild2Id = orgChild2.id;
|
||||||
|
// posMaster.orgRevisionId = orgChild2.orgRevisionId;
|
||||||
|
// SName = orgChild2.orgChild2ShortName;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// posMaster.orgRootId = orgChild1.orgRootId;
|
||||||
|
// posMaster.orgChild1Id = orgChild1.id;
|
||||||
|
// posMaster.orgRevisionId = orgChild1.orgRevisionId;
|
||||||
|
// SName = orgChild1.orgChild1ShortName;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// posMaster.orgRootId = orgRoot.id;
|
||||||
|
// posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
||||||
|
// SName = orgRoot.orgRootShortName;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (posMaster.orgChild4Id != null) {
|
||||||
|
const chk_SName4 = await this.posMasterRepository.findOne({
|
||||||
|
where: {
|
||||||
|
orgChild4Id: posMaster.orgChild4Id,
|
||||||
|
posMasterNo: requestBody.posMasterNo,
|
||||||
|
id: Not(posMaster.id),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (!orgRoot) {
|
if (chk_SName4 != null) {
|
||||||
let orgChild1: any = null;
|
throw new HttpError(
|
||||||
if (requestBody.orgChild1Id != null)
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
orgChild1 = await this.child1Repository.findOne({
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
where: { id: requestBody.orgChild1Id },
|
);
|
||||||
});
|
}
|
||||||
if (!orgChild1) {
|
} else if (posMaster.orgChild3Id != null) {
|
||||||
let orgChild2: any = null;
|
const chk_SName3 = await this.posMasterRepository.findOne({
|
||||||
if (requestBody.orgChild2Id != null)
|
where: {
|
||||||
orgChild2 = await this.child2Repository.findOne({
|
orgChild3Id: posMaster.orgChild3Id,
|
||||||
where: { id: requestBody.orgChild2Id },
|
posMasterNo: requestBody.posMasterNo,
|
||||||
});
|
id: Not(posMaster.id),
|
||||||
if (!orgChild2) {
|
},
|
||||||
let orgChild3: any = null;
|
});
|
||||||
if (requestBody.orgChild3Id != null)
|
if (chk_SName3 != null) {
|
||||||
orgChild3 = await this.child3Repository.findOne({
|
throw new HttpError(
|
||||||
where: { id: requestBody.orgChild3Id },
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
});
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
if (!orgChild3) {
|
);
|
||||||
let orgChild4: any = null;
|
}
|
||||||
if (requestBody.orgChild4Id != null)
|
} else if (posMaster.orgChild2Id != null) {
|
||||||
orgChild4 = await this.child4Repository.findOne({
|
const chk_SName2 = await this.posMasterRepository.findOne({
|
||||||
where: { id: requestBody.orgChild4Id },
|
where: {
|
||||||
});
|
orgChild2Id: posMaster.orgChild2Id,
|
||||||
if (!orgChild4) {
|
posMasterNo: requestBody.posMasterNo,
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
id: Not(posMaster.id),
|
||||||
} else {
|
},
|
||||||
posMaster.orgRootId = orgChild4.orgRootId;
|
});
|
||||||
posMaster.orgChild1Id = orgChild4.orgChild1Id;
|
if (chk_SName2 != null) {
|
||||||
posMaster.orgChild2Id = orgChild4.orgChild2Id;
|
throw new HttpError(
|
||||||
posMaster.orgChild3Id = orgChild4.orgChild3Id;
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
posMaster.orgChild4Id = orgChild4.id;
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
posMaster.orgRevisionId = orgChild4.orgRevisionId;
|
);
|
||||||
SName = orgChild4.orgChild4ShortName;
|
}
|
||||||
}
|
} else if (posMaster.orgChild1Id != null) {
|
||||||
} else {
|
const chk_SName1 = await this.posMasterRepository.findOne({
|
||||||
posMaster.orgRootId = orgChild3.orgRootId;
|
where: {
|
||||||
posMaster.orgChild1Id = orgChild3.orgChild1Id;
|
orgChild1Id: posMaster.orgChild1Id,
|
||||||
posMaster.orgChild2Id = orgChild3.orgChild2Id;
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMaster.orgChild3Id = orgChild3.id;
|
id: Not(posMaster.id),
|
||||||
posMaster.orgRevisionId = orgChild3.orgRevisionId;
|
},
|
||||||
SName = orgChild3.orgChild3ShortName;
|
});
|
||||||
}
|
if (chk_SName1 != null) {
|
||||||
} else {
|
throw new HttpError(
|
||||||
posMaster.orgRootId = orgChild2.orgRootId;
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
posMaster.orgChild1Id = orgChild2.orgChild1Id;
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
posMaster.orgChild2Id = orgChild2.id;
|
);
|
||||||
posMaster.orgRevisionId = orgChild2.orgRevisionId;
|
}
|
||||||
SName = orgChild2.orgChild2ShortName;
|
} else if (posMaster.orgRootId != null) {
|
||||||
}
|
const chk_SName0 = await this.posMasterRepository.findOne({
|
||||||
} else {
|
where: {
|
||||||
posMaster.orgRootId = orgChild1.orgRootId;
|
orgRootId: posMaster.orgRootId,
|
||||||
posMaster.orgChild1Id = orgChild1.id;
|
posMasterNo: requestBody.posMasterNo,
|
||||||
posMaster.orgRevisionId = orgChild1.orgRevisionId;
|
id: Not(posMaster.id),
|
||||||
SName = orgChild1.orgChild1ShortName;
|
},
|
||||||
|
});
|
||||||
|
if (chk_SName0 != null) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
posMaster.orgRootId = orgRoot.id;
|
|
||||||
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
|
||||||
SName = orgRoot.orgRootShortName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const chk_SName0 = await this.posMasterRepository.findOne({
|
// const chk_SName0 = await this.posMasterRepository.findOne({
|
||||||
where: {
|
// where: {
|
||||||
orgRevisionId: posMaster.orgRevisionId,
|
// orgRevisionId: posMaster.orgRevisionId,
|
||||||
orgRoot: { orgRootShortName: SName },
|
// orgRoot: { orgRootShortName: SName },
|
||||||
orgChild1Id: IsNull(),
|
// orgChild1Id: IsNull(),
|
||||||
posMasterNo: requestBody.posMasterNo,
|
// posMasterNo: requestBody.posMasterNo,
|
||||||
id: Not(posMaster.id),
|
// id: Not(posMaster.id),
|
||||||
},
|
// },
|
||||||
relations: ["orgRoot"],
|
// relations: ["orgRoot"],
|
||||||
});
|
// });
|
||||||
if (chk_SName0 != null) {
|
// if (chk_SName0 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const chk_SName1 = await this.posMasterRepository.findOne({
|
// const chk_SName1 = await this.posMasterRepository.findOne({
|
||||||
where: {
|
// where: {
|
||||||
orgRevisionId: posMaster.orgRevisionId,
|
// orgRevisionId: posMaster.orgRevisionId,
|
||||||
orgChild1: { orgChild1ShortName: SName },
|
// orgChild1: { orgChild1ShortName: SName },
|
||||||
orgChild2Id: IsNull(),
|
// orgChild2Id: IsNull(),
|
||||||
posMasterNo: requestBody.posMasterNo,
|
// posMasterNo: requestBody.posMasterNo,
|
||||||
id: Not(posMaster.id),
|
// id: Not(posMaster.id),
|
||||||
},
|
// },
|
||||||
relations: ["orgChild1"],
|
// relations: ["orgChild1"],
|
||||||
});
|
// });
|
||||||
if (chk_SName1 != null) {
|
// if (chk_SName1 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const chk_SName2 = await this.posMasterRepository.findOne({
|
// const chk_SName2 = await this.posMasterRepository.findOne({
|
||||||
where: {
|
// where: {
|
||||||
orgRevisionId: posMaster.orgRevisionId,
|
// orgRevisionId: posMaster.orgRevisionId,
|
||||||
orgChild2: { orgChild2ShortName: SName },
|
// orgChild2: { orgChild2ShortName: SName },
|
||||||
orgChild3Id: IsNull(),
|
// orgChild3Id: IsNull(),
|
||||||
posMasterNo: requestBody.posMasterNo,
|
// posMasterNo: requestBody.posMasterNo,
|
||||||
id: Not(posMaster.id),
|
// id: Not(posMaster.id),
|
||||||
},
|
// },
|
||||||
relations: ["orgChild2"],
|
// relations: ["orgChild2"],
|
||||||
});
|
// });
|
||||||
if (chk_SName2 != null) {
|
// if (chk_SName2 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const chk_SName3 = await this.posMasterRepository.findOne({
|
// const chk_SName3 = await this.posMasterRepository.findOne({
|
||||||
where: {
|
// where: {
|
||||||
orgRevisionId: posMaster.orgRevisionId,
|
// orgRevisionId: posMaster.orgRevisionId,
|
||||||
orgChild3: { orgChild3ShortName: SName },
|
// orgChild3: { orgChild3ShortName: SName },
|
||||||
orgChild4Id: IsNull(),
|
// orgChild4Id: IsNull(),
|
||||||
posMasterNo: requestBody.posMasterNo,
|
// posMasterNo: requestBody.posMasterNo,
|
||||||
id: Not(posMaster.id),
|
// id: Not(posMaster.id),
|
||||||
},
|
// },
|
||||||
relations: ["orgChild3"],
|
// relations: ["orgChild3"],
|
||||||
});
|
// });
|
||||||
if (chk_SName3 != null) {
|
// if (chk_SName3 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const chk_SName4 = await this.posMasterRepository.findOne({
|
// const chk_SName4 = await this.posMasterRepository.findOne({
|
||||||
where: {
|
// where: {
|
||||||
orgRevisionId: posMaster.orgRevisionId,
|
// orgRevisionId: posMaster.orgRevisionId,
|
||||||
orgChild4: { orgChild4ShortName: SName },
|
// orgChild4: { orgChild4ShortName: SName },
|
||||||
posMasterNo: requestBody.posMasterNo,
|
// posMasterNo: requestBody.posMasterNo,
|
||||||
id: Not(posMaster.id),
|
// id: Not(posMaster.id),
|
||||||
},
|
// },
|
||||||
relations: ["orgChild4"],
|
// relations: ["orgChild4"],
|
||||||
});
|
// });
|
||||||
if (chk_SName4 != null) {
|
// if (chk_SName4 != null) {
|
||||||
throw new HttpError(
|
// throw new HttpError(
|
||||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
// HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
// "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้
|
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;
|
||||||
posMaster.lastUpdateFullName = request.user.name;
|
posMaster.lastUpdateFullName = request.user.name;
|
||||||
|
|
@ -1631,7 +1703,11 @@ export class PositionController extends Controller {
|
||||||
});
|
});
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
|
where: {
|
||||||
|
orgRootId: org.id,
|
||||||
|
posMasterNo: posMaster.posMasterNo,
|
||||||
|
orgChild1Id: IsNull() || "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (_posMaster != null)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|
@ -1660,7 +1736,11 @@ export class PositionController extends Controller {
|
||||||
});
|
});
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
|
where: {
|
||||||
|
orgChild1Id: org.id,
|
||||||
|
posMasterNo: posMaster.posMasterNo,
|
||||||
|
orgChild2Id: IsNull() || "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (_posMaster != null)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|
@ -1688,7 +1768,11 @@ export class PositionController extends Controller {
|
||||||
});
|
});
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
|
where: {
|
||||||
|
orgChild2Id: org.id,
|
||||||
|
posMasterNo: posMaster.posMasterNo,
|
||||||
|
orgChild3Id: IsNull() || "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (_posMaster != null)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|
@ -1715,7 +1799,11 @@ export class PositionController extends Controller {
|
||||||
});
|
});
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
|
where: {
|
||||||
|
orgChild3Id: org.id,
|
||||||
|
posMasterNo: posMaster.posMasterNo,
|
||||||
|
orgChild4Id: IsNull() || "",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (_posMaster != null)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|
@ -1737,7 +1825,10 @@ export class PositionController extends Controller {
|
||||||
});
|
});
|
||||||
if (org != null) {
|
if (org != null) {
|
||||||
const _posMaster = await this.posMasterRepository.findOne({
|
const _posMaster = await this.posMasterRepository.findOne({
|
||||||
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
|
where: {
|
||||||
|
orgChild4Id: org.id,
|
||||||
|
posMasterNo: posMaster.posMasterNo,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
if (_posMaster != null)
|
if (_posMaster != null)
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue