เพิ่มเหตุผล posmaster

This commit is contained in:
Kittapath 2024-04-09 12:18:52 +07:00
parent 7a2ed91612
commit 013ccf60e6
7 changed files with 433 additions and 72 deletions

View file

@ -471,6 +471,7 @@ export class PositionController extends Controller {
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
reason: "บริหาร",
positions: [
{
posDictName: "นักบริหาร",
@ -745,6 +746,7 @@ export class PositionController extends Controller {
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
reason: "บริหาร",
positions: [
{
posDictName: "นักบริหาร",
@ -770,6 +772,7 @@ export class PositionController extends Controller {
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
posMaster.reason = requestBody.reason;
posMaster.orgRootId = null;
posMaster.orgChild1Id = null;
posMaster.orgChild2Id = null;
@ -982,6 +985,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
positions: positions.map((position) => ({
id: position.id,
positionName: position.positionName,
@ -1303,6 +1307,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
fullNameCurrentHolder:
posMaster.current_holder == null
? null
@ -1536,6 +1541,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: item.posMasterNoPrefix ? item.posMasterNoPrefix : null,
posMasterNo: item.posMasterNo ? item.posMasterNo : null,
posMasterNoSuffix: item.posMasterNoSuffix ? item.posMasterNoSuffix : null,
reason: item.reason ? item.reason : null,
}));
return new HttpSuccess(_data);
}
@ -1612,7 +1618,7 @@ export class PositionController extends Controller {
...type4LastPosMasterNo,
];
let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
// let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
posMasters.forEach(async (posMaster: any) => {
@ -1623,6 +1629,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgRootId == org.id &&
posMaster.orgChild1Id == null &&
@ -1644,6 +1658,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild1Id == org.id &&
posMaster.orgChild2Id == null &&
@ -1664,6 +1686,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild2Id == org.id &&
posMaster.orgChild3Id == null &&
@ -1683,6 +1713,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1697,6 +1735,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild4Id == org.id) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1707,7 +1753,6 @@ export class PositionController extends Controller {
}
}
if (change == true) {
posMaster.posMasterNo = maxPosMasterNo += 1;
posMaster.posMasterOrder = maxPosMasterOrder += 1;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;