โครงการเพิ่มบันทึกยุทธศาสตร์
This commit is contained in:
parent
650c6fe3e3
commit
be703f8e3b
16 changed files with 930 additions and 84 deletions
|
|
@ -11,7 +11,6 @@ import {
|
|||
Path,
|
||||
Request,
|
||||
Query,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { In, Not } from "typeorm";
|
||||
|
|
@ -22,8 +21,6 @@ import {
|
|||
Development,
|
||||
CreateDevelopment,
|
||||
UpdateDevelopment1,
|
||||
UpdateDevelopment2_1,
|
||||
UpdateDevelopment2_2,
|
||||
UpdateDevelopment3,
|
||||
UpdateDevelopment4,
|
||||
UpdateDevelopment5,
|
||||
|
|
@ -45,6 +42,11 @@ import {
|
|||
import { DevelopmentAddress } from "../entities/DevelopmentAddress";
|
||||
import { DevelopmentProjectTechniquePlanned } from "../entities/DevelopmentProjectTechniquePlanned";
|
||||
import { DevelopmentProjectTechniqueActual } from "../entities/DevelopmentProjectTechniqueActual";
|
||||
import { StrategyChild1 } from "../entities/StrategyChild1";
|
||||
import { StrategyChild2 } from "../entities/StrategyChild2";
|
||||
import { StrategyChild3 } from "../entities/StrategyChild3";
|
||||
import { StrategyChild4 } from "../entities/StrategyChild4";
|
||||
import { StrategyChild5 } from "../entities/StrategyChild5";
|
||||
|
||||
@Route("api/v1/development/main")
|
||||
@Tags("Development")
|
||||
|
|
@ -69,6 +71,11 @@ export class DevelopmentController extends Controller {
|
|||
private provinceRepository = AppDataSource.getRepository(Province);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1);
|
||||
private strategyChild2Repository = AppDataSource.getRepository(StrategyChild2);
|
||||
private strategyChild3Repository = AppDataSource.getRepository(StrategyChild3);
|
||||
private strategyChild4Repository = AppDataSource.getRepository(StrategyChild4);
|
||||
private strategyChild5Repository = AppDataSource.getRepository(StrategyChild5);
|
||||
|
||||
/**
|
||||
* API เพิ่มโครงการ/หลักสูตรการฝึกอบรม
|
||||
|
|
@ -97,8 +104,188 @@ 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;
|
||||
|
|
@ -143,6 +330,187 @@ 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;
|
||||
|
|
@ -988,6 +1356,16 @@ export class DevelopmentController extends Controller {
|
|||
"rootId",
|
||||
"orgRootShortName",
|
||||
"orgRevisionId",
|
||||
"strategyChild1Planned",
|
||||
"strategyChild2Planned",
|
||||
"strategyChild3Planned",
|
||||
"strategyChild4Planned",
|
||||
"strategyChild5Planned",
|
||||
"strategyChild1Actual",
|
||||
"strategyChild2Actual",
|
||||
"strategyChild3Actual",
|
||||
"strategyChild4Actual",
|
||||
"strategyChild5Actual",
|
||||
],
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
|
|
@ -1191,31 +1569,37 @@ export class DevelopmentController extends Controller {
|
|||
*/
|
||||
@Get("tab6/{id}")
|
||||
async GetDevelopemtTab6ById(@Path() id: string) {
|
||||
const getDevelopment = await this.developmentRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: [
|
||||
"developmentActualPeoples",
|
||||
"developmentPlannedPeoples",
|
||||
"developmentActualGoals",
|
||||
"developmentPlannedGoals",
|
||||
"developmentPlannedGoals.plannedGoalPositions",
|
||||
"provinces",
|
||||
// "provinces.developmentProvinces",
|
||||
],
|
||||
const getDevelopment = await this.developmentHistoryRepository.find({
|
||||
where: { developmentId: id },
|
||||
relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"],
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||
}
|
||||
let _getDevelopment: any = getDevelopment;
|
||||
_getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples;
|
||||
_getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples;
|
||||
_getDevelopment.actualGoals = getDevelopment.developmentActualGoals;
|
||||
_getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals;
|
||||
// _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces);
|
||||
delete _getDevelopment.developmentActualPeoples;
|
||||
delete _getDevelopment.developmentPlannedPeoples;
|
||||
delete _getDevelopment.developmentActualGoals;
|
||||
delete _getDevelopment.developmentPlannedGoals;
|
||||
const _getDevelopment = getDevelopment.map((item) => ({
|
||||
id: item.id,
|
||||
citizenId: item.citizenId,
|
||||
fullName: item.prefix + item.firstName + " " + item.lastName,
|
||||
position: item.position,
|
||||
posType:
|
||||
item.type == "OFFICER"
|
||||
? item.posType
|
||||
? item.posType.posTypeName
|
||||
: null
|
||||
: item.employeePosType
|
||||
? item.employeePosType.posTypeName
|
||||
: null,
|
||||
posLevel:
|
||||
item.type == "OFFICER"
|
||||
? item.posLevel
|
||||
? item.posLevel.posLevelName
|
||||
: null
|
||||
: item.employeePosLevel
|
||||
? item.employeePosLevel.posLevelName
|
||||
: null,
|
||||
posExecutive: item.posExecutive,
|
||||
root: item.root,
|
||||
order: item.order,
|
||||
dateOrder: item.dateOrder,
|
||||
isDone: item.isDone,
|
||||
}));
|
||||
return new HttpSuccess(_getDevelopment);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue