From dbf0952b6b73d8eb62297ef5216fd10699ca6483 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 14 Mar 2025 15:17:32 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=95=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=8A=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=A7=E0=B8=84=E0=B8=A3=E0=B8=B2=E0=B8=A7=20?= =?UTF-8?q?=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EmployeeTempPositionController.ts | 310 +++++++++--------- src/entities/EmployeeTempPosMaster.ts | 6 +- 2 files changed, 159 insertions(+), 157 deletions(-) diff --git a/src/controllers/EmployeeTempPositionController.ts b/src/controllers/EmployeeTempPositionController.ts index deb32067..a4975673 100644 --- a/src/controllers/EmployeeTempPositionController.ts +++ b/src/controllers/EmployeeTempPositionController.ts @@ -531,84 +531,84 @@ export class EmployeeTempPositionController extends Controller { 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_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_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_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_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 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; @@ -652,7 +652,9 @@ export class EmployeeTempPositionController extends Controller { @Request() request: RequestWithUser, ) { await new permission().PermissionUpdate(request, "SYS_ORG_TEMP"); - const posMaster = await this.employeeTempPosMasterRepository.findOne({ where: { id: id } }); + const posMaster: any = await this.employeeTempPosMasterRepository.findOne({ + where: { id: id }, + }); if (!posMaster) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); } @@ -739,89 +741,89 @@ export class EmployeeTempPositionController extends Controller { 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_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_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_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_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 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; diff --git a/src/entities/EmployeeTempPosMaster.ts b/src/entities/EmployeeTempPosMaster.ts index 82112df1..7486f15b 100644 --- a/src/entities/EmployeeTempPosMaster.ts +++ b/src/entities/EmployeeTempPosMaster.ts @@ -235,13 +235,13 @@ export class EmployeeTempPosMaster extends EntityBase { export class CreateEmployeeTempPosMaster { @Column() - posMasterNoPrefix: string; + posMasterNoPrefix?: string | null; @Column() - posMasterNo: number; + posMasterNo?: number | null; @Column() - posMasterNoSuffix: string; + posMasterNoSuffix?: string | null; @Column("uuid") positions: CreateEmployeePosDict[];