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