แก้ไขตำแหน่ง

This commit is contained in:
kittapath 2025-03-14 15:48:52 +07:00
parent dbf0952b6b
commit c778b52e8b

View file

@ -530,85 +530,6 @@ export class EmployeeTempPositionController extends Controller {
posMaster.orgRevisionId = orgRoot.orgRevisionId;
SName = orgRoot.orgRootShortName;
}
// const chk_SName0 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgRoot: { orgRootShortName: SName },
// orgChild1Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// },
// relations: ["orgRoot"],
// });
// // if (chk_SName0 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild1: { orgChild1ShortName: SName },
// orgChild2Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// },
// relations: ["orgChild1"],
// });
// // if (chk_SName1 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild2: { orgChild2ShortName: SName },
// orgChild3Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// },
// relations: ["orgChild2"],
// });
// // if (chk_SName2 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild3: { orgChild3ShortName: SName },
// orgChild4Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// },
// relations: ["orgChild3"],
// });
// // if (chk_SName3 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild4: { orgChild4ShortName: SName },
// posMasterNo: requestBody.posMasterNo,
// },
// relations: ["orgChild4"],
// });
// // if (chk_SName4 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
const before = null;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;
@ -740,90 +661,6 @@ export class EmployeeTempPositionController extends Controller {
posMaster.orgRevisionId = orgRoot.orgRevisionId;
SName = orgRoot.orgRootShortName;
}
// const chk_SName0 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgRoot: { orgRootShortName: SName },
// orgChild1Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// id: Not(posMaster.id),
// },
// relations: ["orgRoot"],
// });
// // if (chk_SName0 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName1 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild1: { orgChild1ShortName: SName },
// orgChild2Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// id: Not(posMaster.id),
// },
// relations: ["orgChild1"],
// });
// // if (chk_SName1 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName2 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild2: { orgChild2ShortName: SName },
// orgChild3Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// id: Not(posMaster.id),
// },
// relations: ["orgChild2"],
// });
// // if (chk_SName2 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName3 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild3: { orgChild3ShortName: SName },
// orgChild4Id: IsNull(),
// posMasterNo: requestBody.posMasterNo,
// id: Not(posMaster.id),
// },
// relations: ["orgChild3"],
// });
// // if (chk_SName3 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
// const chk_SName4 = await this.employeeTempPosMasterRepository.findOne({
// where: {
// orgRevisionId: posMaster.orgRevisionId,
// orgChild4: { orgChild4ShortName: SName },
// posMasterNo: requestBody.posMasterNo,
// id: Not(posMaster.id),
// },
// relations: ["orgChild4"],
// });
// // if (chk_SName4 != null) {
// // throw new HttpError(
// // HttpStatusCode.INTERNAL_SERVER_ERROR,
// // "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
// // );
// // }
const before = structuredClone(posMaster);
posMaster.createdUserId = request.user.sub; //สงสัยว่าทำให้ bug แก้ไขไม่ได้
posMaster.createdFullName = request.user.name;
@ -855,43 +692,6 @@ export class EmployeeTempPositionController extends Controller {
return new HttpSuccess(posMaster.id);
}
/**
* API
*
* @summary ORG_ - (ADMIN)
*
*/
// @Get("position/{id}")
// async detailEmpPosition(@Path() id: string) {
// const posMaster = await this.employeeTempPosMasterRepository.findOne({
// where: { id },
// });
// if (!posMaster) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// }
// const positions = await this.employeePositionRepository.find({
// where: { posMasterTempId: posMaster.id },
// relations: ["posType", "posLevel"],
// order: { lastUpdatedAt: "ASC" },
// });
// const formattedData = {
// id: posMaster.id,
// posMasterNoPrefix: posMaster.posMasterNoPrefix,
// posMasterNo: posMaster.posMasterNo,
// posMasterNoSuffix: posMaster.posMasterNoSuffix,
// positions: positions.map((position) => ({
// id: position.id,
// positionName: position.positionName,
// posTypeId: position.posTypeId,
// posTypeName: position.posType == null ? null : position.posType.posTypeName,
// posLevelId: position.posLevelId,
// posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
// positionIsSelected: position.positionIsSelected,
// })),
// };
// return new HttpSuccess(formattedData);
// }
/**
* API
*
@ -1553,14 +1353,6 @@ export class EmployeeTempPositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeeTempPosMasterRepository.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 &&
@ -1582,14 +1374,6 @@ export class EmployeeTempPositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeeTempPosMasterRepository.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 &&
@ -1610,14 +1394,6 @@ export class EmployeeTempPositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeeTempPosMasterRepository.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 &&
@ -1637,14 +1413,6 @@ export class EmployeeTempPositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeeTempPosMasterRepository.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;
@ -1659,14 +1427,6 @@ export class EmployeeTempPositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeeTempPosMasterRepository.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;