เพิ่ม/แก้ไข กลุ่มเป้าหมาย (ลูกจ้าง)

This commit is contained in:
Bright 2025-04-10 16:20:30 +07:00
parent 719da25875
commit 60781ea254

View file

@ -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;