no message

This commit is contained in:
Kittapath 2024-04-17 15:27:37 +07:00
parent d21704baaf
commit e9a6f00431
4 changed files with 230 additions and 386 deletions

View file

@ -109,188 +109,7 @@ export class DevelopmentController extends Controller {
" มีอยู่ในระบบแล้ว",
);
}
let _null: any = null;
const development = Object.assign(new Development(), requestBody);
switch (requestBody.strategyChildPlannedNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1",
);
}
development.strategyChild1PlannedId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.strategyChild4Id;
development.strategyChild5PlannedId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน");
}
switch (requestBody.strategyChildActualNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1",
);
}
development.strategyChild1ActualId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.strategyChild4Id;
development.strategyChild5ActualId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง");
}
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
@ -335,187 +154,6 @@ export class DevelopmentController extends Controller {
" มีอยู่ในระบบแล้ว",
);
}
let _null: any = null;
switch (requestBody.strategyChildPlannedNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1",
);
}
development.strategyChild1PlannedId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.strategyChild4Id;
development.strategyChild5PlannedId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน");
}
switch (requestBody.strategyChildActualNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1",
);
}
development.strategyChild1ActualId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.strategyChild4Id;
development.strategyChild5ActualId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง");
}
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
@ -1000,6 +638,197 @@ export class DevelopmentController extends Controller {
}),
);
}
const _null: any = null;
if (
requestBody.strategyChildPlannedNode != undefined &&
requestBody.strategyChildPlannedNode != null
) {
switch (requestBody.strategyChildPlannedNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1",
);
}
development.strategyChild1PlannedId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 3",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 2",
);
}
development.strategyChild1PlannedId = checkId.strategyChild1Id;
development.strategyChild2PlannedId = checkId.strategyChild2Id;
development.strategyChild3PlannedId = checkId.strategyChild3Id;
development.strategyChild4PlannedId = checkId.strategyChild4Id;
development.strategyChild5PlannedId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน");
}
}
if (
requestBody.strategyChildActualNode != undefined &&
requestBody.strategyChildActualNode != null
) {
switch (requestBody.strategyChildActualNode) {
case 1: {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 1",
);
}
development.strategyChild1ActualId = checkId.id;
development.strategyChild2ActualId = _null;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 2: {
const checkId = await this.strategyChild2Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 2",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.id;
development.strategyChild3ActualId = _null;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 3: {
const checkId = await this.strategyChild3Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 3",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.id;
development.strategyChild4ActualId = _null;
development.strategyChild5ActualId = _null;
break;
}
case 4: {
const checkId = await this.strategyChild4Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 4",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.id;
development.strategyChild5ActualId = _null;
break;
}
case 5: {
const checkId = await this.strategyChild5Repository.findOne({
where: { id: requestBody.strategyChildActualId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริงระดับ 5",
);
}
development.strategyChild1ActualId = checkId.strategyChild1Id;
development.strategyChild2ActualId = checkId.strategyChild2Id;
development.strategyChild3ActualId = checkId.strategyChild3Id;
development.strategyChild4ActualId = checkId.strategyChild4Id;
development.strategyChild5ActualId = checkId.id;
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง");
}
}
return new HttpSuccess(development.id);
}
@ -1361,16 +1190,6 @@ export class DevelopmentController extends Controller {
"rootId",
"orgRootShortName",
"orgRevisionId",
"strategyChild1Planned",
"strategyChild2Planned",
"strategyChild3Planned",
"strategyChild4Planned",
"strategyChild5Planned",
"strategyChild1Actual",
"strategyChild2Actual",
"strategyChild3Actual",
"strategyChild4Actual",
"strategyChild5Actual",
],
});
if (!getDevelopment) {
@ -1456,6 +1275,7 @@ export class DevelopmentController extends Controller {
.map((x) => ({
groupTarget: x.groupTarget,
groupTargetSub: x.groupTargetSub,
type: x.type,
position: x.plannedGoalPositions.map((y) => ({
position: y.position,
posTypeId: y.posTypePlannedId,
@ -1509,6 +1329,16 @@ export class DevelopmentController extends Controller {
developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals
.map((x) => x.name)
.sort(),
strategyChild1Planned: getDevelopment.strategyChild1Planned,
strategyChild2Planned: getDevelopment.strategyChild2Planned,
strategyChild3Planned: getDevelopment.strategyChild3Planned,
strategyChild4Planned: getDevelopment.strategyChild4Planned,
strategyChild5Planned: getDevelopment.strategyChild5Planned,
strategyChild1Actual: getDevelopment.strategyChild1Actual,
strategyChild2Actual: getDevelopment.strategyChild2Actual,
strategyChild3Actual: getDevelopment.strategyChild3Actual,
strategyChild4Actual: getDevelopment.strategyChild4Actual,
strategyChild5Actual: getDevelopment.strategyChild5Actual,
};
return new HttpSuccess(_getDevelopment);
}