From 60781ea2544e05eb3ec14c5d826be5e217238b59 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 10 Apr 2025 16:20:30 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1/?= =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=20=E0=B8=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B9=80=E0=B8=9B=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=AB=E0=B8=A1=E0=B8=B2=E0=B8=A2=20(=E0=B8=A5?= =?UTF-8?q?=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 88 ++++++++++++++++++------ 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 0e8e115..4310ce9 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -34,6 +34,8 @@ import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { CreateDevelopmentHistoryOBO, DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; @@ -84,6 +86,8 @@ export class DevelopmentController extends Controller { private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private empPosTypeRepository = AppDataSource.getRepository(EmployeePosType); + private empPosLevelRepository = AppDataSource.getRepository(EmployeePosLevel); private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1); private strategyChild2Repository = AppDataSource.getRepository(StrategyChild2); private strategyChild3Repository = AppDataSource.getRepository(StrategyChild3); @@ -367,19 +371,41 @@ export class DevelopmentController extends Controller { requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkId:any + if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + } + else { + checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + let checkId:any + if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } const before = structuredClone(development); @@ -608,19 +634,41 @@ export class DevelopmentController extends Controller { requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkId:any + if(requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + } + else { + checkId = await this.posTypeRepository.findOne({ + where: { id: x.posTypePlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + let checkId:any + if (requestBody.groupTarget == "PERSONNEL" && (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) { + checkId = await this.empPosLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } + else { + checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } _data.createdUserId = request.user.sub;