This commit is contained in:
Bright 2025-04-11 15:38:32 +07:00
parent dbfc678e92
commit 2e7bef0475

View file

@ -370,44 +370,54 @@ export class DevelopmentController extends Controller {
await Promise.all(
requestBody.positions.map(async (x) => {
const _data = Object.assign(new PlannedGoalPosition(), x);
// if (x.posTypePlannedId != null) {
// 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) {
// 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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
// }
let checkPosType:any = null
let posTypeShortName:any = null
if (x.posTypePlanned != null) {
if(requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosType = await this.empPosTypeRepository.findOne({
where: { posTypeName: x.posTypePlanned },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
}
posTypeShortName = checkPosType.posTypeShortName
}
else {
checkPosType = await this.posTypeRepository.findOne({
where: { posTypeName: x.posTypePlanned },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
}
}
}
if (x.posLevelPlanned != null) {
let checkPosLevel:any
if (requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosLevel = await this.empPosLevelRepository.find({
where: {
posTypeId: checkPosType.id
},
});
const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`);
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
}
}
else {
checkPosLevel = await this.posLevelRepository.findOne({
where: {
posLevelName: x.posLevelPlanned,
posTypeId: checkPosType.id
},
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
}
}
}
const before = structuredClone(development);
_data.createdUserId = request.user.sub;
_data.createdFullName = request.user.name;
@ -492,32 +502,54 @@ export class DevelopmentController extends Controller {
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
// if (requestBody.posTypeActualId != null) {
// // addLogSequence(request, {
// // action: "database",
// // status: "success",
// // description: "Get Position Type.",
// // });
// const checkId = await this.posTypeRepository.findOne({
// where: { id: requestBody.posTypeActualId },
// });
// if (!checkId) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
// }
// }
// if (requestBody.posLevelActualId != null) {
// // addLogSequence(request, {
// // action: "database",
// // status: "success",
// // description: "Get Position Level.",
// // });
// const checkId = await this.posLevelRepository.findOne({
// where: { id: requestBody.posLevelActualId },
// });
// if (!checkId) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
let checkPosType:any = null
let posTypeShortName:any = null
if (requestBody.posTypeActual != null) {
if(requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosType = await this.empPosTypeRepository.findOne({
where: { posTypeName: requestBody.posTypeActual },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
}
posTypeShortName = checkPosType.posTypeShortName
}
else {
checkPosType = await this.posTypeRepository.findOne({
where: { posTypeName: requestBody.posTypeActual },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
}
}
}
if (requestBody.posLevelActual != null) {
let checkPosLevel:any
if (requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosLevel = await this.empPosLevelRepository.find({
where: {
posTypeId: checkPosType.id
},
});
const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`);
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
}
}
else {
checkPosLevel = await this.posLevelRepository.findOne({
where: {
posLevelName: requestBody.posLevelActual,
posTypeId: checkPosType.id
},
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
}
}
}
const before = structuredClone(development);
const data = Object.assign(new ActualGoal(), requestBody);
data.createdUserId = request.user.sub;
@ -633,44 +665,54 @@ export class DevelopmentController extends Controller {
await Promise.all(
requestBody.positions.map(async (x) => {
const _data = Object.assign(new PlannedGoalPosition(), x);
// if (x.posTypePlannedId != null) {
// 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) {
// 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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
// }
let checkPosType:any = null
let posTypeShortName:any = null
if (x.posTypePlanned != null) {
if(requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosType = await this.empPosTypeRepository.findOne({
where: { posTypeName: x.posTypePlanned },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
}
posTypeShortName = checkPosType.posTypeShortName
}
else {
checkPosType = await this.posTypeRepository.findOne({
where: { posTypeName: x.posTypePlanned },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
}
}
}
if (x.posLevelPlanned != null) {
let checkPosLevel:any
if (requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosLevel = await this.empPosLevelRepository.find({
where: {
posTypeId: checkPosType.id
},
});
const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`);
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
}
}
else {
checkPosLevel = await this.posLevelRepository.findOne({
where: {
posLevelName: x.posLevelPlanned,
posTypeId: checkPosType.id
},
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
}
}
}
_data.createdUserId = request.user.sub;
_data.createdFullName = request.user.name;
_data.lastUpdateUserId = request.user.sub;
@ -759,32 +801,54 @@ export class DevelopmentController extends Controller {
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
// if (requestBody.posTypeActualId != null) {
// // addLogSequence(request, {
// // action: "database",
// // status: "success",
// // description: "Get Position Type.",
// // });
// const checkId = await this.posTypeRepository.findOne({
// where: { id: requestBody.posTypeActualId },
// });
// if (!checkId) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
// }
// }
// if (requestBody.posLevelActualId != null) {
// // addLogSequence(request, {
// // action: "database",
// // status: "success",
// // description: "Get Position Level.",
// // });
// const checkId = await this.posLevelRepository.findOne({
// where: { id: requestBody.posLevelActualId },
// });
// if (!checkId) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
let checkPosType:any = null
let posTypeShortName:any = null
if (requestBody.posTypeActual != null) {
if(requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosType = await this.empPosTypeRepository.findOne({
where: { posTypeName: requestBody.posTypeActual },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
}
posTypeShortName = checkPosType.posTypeShortName
}
else {
checkPosType = await this.posTypeRepository.findOne({
where: { posTypeName: requestBody.posTypeActual },
});
if (!checkPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
}
}
}
if (requestBody.posLevelActual != null) {
let checkPosLevel:any
if (requestBody.groupTarget == "PERSONNEL" &&
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")) {
checkPosLevel = await this.empPosLevelRepository.find({
where: {
posTypeId: checkPosType.id
},
});
const mapShortName = checkPosLevel.flatMap((x:any) => `${posTypeShortName} ${x.posLevelName}`);
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
}
}
else {
checkPosLevel = await this.posLevelRepository.findOne({
where: {
posLevelName: requestBody.posLevelActual,
posTypeId: checkPosType.id
},
});
if (!checkPosLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
}
}
}
const before = structuredClone(development);
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;