hrms-api-development/src/controllers/DevelopmentController.ts

3259 lines
138 KiB
TypeScript
Raw Normal View History

2024-04-02 17:53:45 +07:00
import {
Controller,
Get,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
Request,
Query,
UploadedFile,
2024-04-02 17:53:45 +07:00
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { In, Not } from "typeorm";
2024-04-02 17:53:45 +07:00
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
2024-04-11 11:39:56 +07:00
import {
Development,
CreateDevelopment,
UpdateDevelopment1,
UpdateDevelopment3,
UpdateDevelopment4,
UpdateDevelopment5,
2024-08-07 14:03:40 +07:00
UpdateDevelopment7,
UpdateDevelopment8,
2024-04-11 11:39:56 +07:00
} from "../entities/Development";
import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople";
import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople";
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";
2024-04-11 11:39:56 +07:00
import { DevelopmentProjectType } from "../entities/DevelopmentProjectType";
2024-04-11 16:32:44 +07:00
import {
CreateDevelopmentEvaluation,
DevelopmentEvaluation,
} from "../entities/DevelopmentEvaluation";
2024-04-11 11:39:56 +07:00
import { DevelopmentAddress } from "../entities/DevelopmentAddress";
2024-04-11 16:32:44 +07:00
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";
import CallAPI from "../interfaces/call-api";
import { UseInterceptors } from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import * as xlsx from "xlsx";
2024-09-03 15:18:30 +07:00
import { setLogDataDiff } from "../interfaces/utils";
2024-07-25 17:06:42 +07:00
import { RequestWithUser } from "../middlewares/user";
2024-08-07 18:15:55 +07:00
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
2024-08-08 11:27:28 +07:00
import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther";
2024-08-09 17:08:28 +07:00
import permission from "../interfaces/permission";
2024-12-19 13:26:30 +07:00
import { Brackets } from "typeorm";
2024-04-02 17:53:45 +07:00
@Route("api/v1/development/main")
@Tags("Development")
@Security("bearerAuth")
export class DevelopmentController extends Controller {
private developmentRepository = AppDataSource.getRepository(Development);
2024-08-07 17:34:44 +07:00
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
2024-08-08 11:27:28 +07:00
private developmentOtherRepository = AppDataSource.getRepository(DevelopmentOther);
2024-04-11 11:39:56 +07:00
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
2024-04-11 16:32:44 +07:00
private developmentProjectTechniquePlannedRepository = AppDataSource.getRepository(
DevelopmentProjectTechniquePlanned,
);
private developmentProjectTechniqueActualRepository = AppDataSource.getRepository(
DevelopmentProjectTechniqueActual,
2024-04-11 11:39:56 +07:00
);
private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory);
private actualPeopleRepository = AppDataSource.getRepository(ActualPeople);
private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople);
private actualGoalRepository = AppDataSource.getRepository(ActualGoal);
private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal);
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);
private strategyChild4Repository = AppDataSource.getRepository(StrategyChild4);
private strategyChild5Repository = AppDataSource.getRepository(StrategyChild5);
2024-04-02 17:53:45 +07:00
2024-12-19 11:41:06 +07:00
/**
* API
*
* @summary
*
*/
@Get("clear-db")
async ClearDb() {
return new HttpSuccess();
}
2024-04-02 17:53:45 +07:00
/**
* API /
*
* @summary DEV_001 - /#1
*
*/
@Post()
async CreateDevelopment(
@Body() requestBody: CreateDevelopment,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-02 17:53:45 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-02 17:53:45 +07:00
const chk_name = await this.developmentRepository.find({
where: {
projectName: requestBody.projectName,
year: requestBody.year,
2024-04-02 17:53:45 +07:00
},
});
if (chk_name.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"โครงการ/หลักสูตรการฝึกอบรม: " +
requestBody.projectName +
" ปีงบประมาณ: " +
2024-04-03 16:14:00 +07:00
(requestBody.year + 543) +
" มีอยู่ในระบบแล้ว",
2024-04-02 17:53:45 +07:00
);
}
2024-04-18 14:50:49 +07:00
const development = Object.assign(new Development(), requestBody);
await new CallAPI()
2024-07-10 10:45:01 +07:00
.PostData(request, "/org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
development.root = x.root;
development.rootId = x.rootId;
2025-01-30 08:53:02 +07:00
development.rootDnaId = x.rootDnaId;
development.rootShortName = x.rootShortName;
development.child1 = x.child1;
development.child1Id = x.child1Id;
2025-01-30 08:53:02 +07:00
development.child1DnaId = x.child1DnaId;
development.child1ShortName = x.child1ShortName;
development.child2 = x.child2;
development.child2Id = x.child2Id;
2025-01-30 08:53:02 +07:00
development.child2DnaId = x.child2DnaId;
development.child2ShortName = x.child2ShortName;
development.child3 = x.child3;
development.child3Id = x.child3Id;
2025-01-30 08:53:02 +07:00
development.child3DnaId = x.child3DnaId;
development.child3ShortName = x.child3ShortName;
development.child4 = x.child4;
development.child4Id = x.child4Id;
2025-01-30 08:53:02 +07:00
development.child4DnaId = x.child4DnaId;
development.child4ShortName = x.child4ShortName;
})
2024-04-18 14:50:49 +07:00
.catch((error) => {
console.error("Error calling API:", error);
});
2024-04-02 17:53:45 +07:00
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-26 16:30:38 +07:00
const before = null;
2024-07-25 17:06:42 +07:00
await this.developmentRepository.save(development, { data: request });
2024-07-26 16:30:38 +07:00
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API / Tab1
*
* @summary DEV_00 - /Tab1 #
*
* @param {string} id Id
*/
@Put("tab1/{id}")
async UpdateDevelopmentTab1(
@Path() id: string,
@Body() requestBody: UpdateDevelopment1,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const chk_name = await this.developmentRepository.find({
where: {
projectName: requestBody.projectName,
year: requestBody.year,
id: Not(id),
},
});
if (chk_name.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"โครงการ/หลักสูตรการฝึกอบรม: " +
requestBody.projectName +
" ปีงบประมาณ: " +
(requestBody.year + 543) +
" มีอยู่ในระบบแล้ว",
);
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
Object.assign(development, requestBody);
await new CallAPI()
2024-07-10 10:45:01 +07:00
.PostData(request, "/org/find/all", {
node: requestBody.node,
nodeId: requestBody.nodeId,
})
.then((x) => {
development.root = x.root;
development.rootId = x.rootId;
2025-01-30 08:53:02 +07:00
development.rootDnaId = x.rootDnaId;
development.rootShortName = x.rootShortName;
development.child1 = x.child1;
development.child1Id = x.child1Id;
2025-01-30 08:53:02 +07:00
development.child1DnaId = x.child1DnaId;
development.child1ShortName = x.child1ShortName;
development.child2 = x.child2;
development.child2Id = x.child2Id;
2025-01-30 08:53:02 +07:00
development.child2DnaId = x.child2DnaId;
development.child2ShortName = x.child2ShortName;
development.child3 = x.child3;
development.child3Id = x.child3Id;
2025-01-30 08:53:02 +07:00
development.child3DnaId = x.child3DnaId;
development.child3ShortName = x.child3ShortName;
development.child4 = x.child4;
development.child4Id = x.child4Id;
2025-01-30 08:53:02 +07:00
development.child4DnaId = x.child4DnaId;
development.child4ShortName = x.child4ShortName;
})
.catch((x) => {});
2024-04-18 14:50:49 +07:00
const _null: any = null;
switch (requestBody.node) {
case 0: {
development.child1 = _null;
development.child1Id = _null;
2025-01-30 08:53:02 +07:00
development.child1DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child1ShortName = _null;
development.child2 = _null;
development.child2Id = _null;
2025-01-30 08:53:02 +07:00
development.child2DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child2ShortName = _null;
development.child3 = _null;
development.child3Id = _null;
2025-01-30 08:53:02 +07:00
development.child3DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child3ShortName = _null;
development.child4 = _null;
development.child4Id = _null;
2025-01-30 08:53:02 +07:00
development.child4DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child4ShortName = _null;
break;
}
case 1: {
development.child2 = _null;
development.child2Id = _null;
2025-01-30 08:53:02 +07:00
development.child2DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child2ShortName = _null;
development.child3 = _null;
development.child3Id = _null;
2025-01-30 08:53:02 +07:00
development.child3DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child3ShortName = _null;
development.child4 = _null;
development.child4Id = _null;
2025-01-30 08:53:02 +07:00
development.child4DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child4ShortName = _null;
break;
}
case 2: {
development.child3 = _null;
development.child3Id = _null;
2025-01-30 08:53:02 +07:00
development.child3DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child3ShortName = _null;
development.child4 = _null;
development.child4Id = _null;
2025-01-30 08:53:02 +07:00
development.child4DnaId = _null;
2024-04-18 14:50:49 +07:00
development.child4ShortName = _null;
break;
}
case 3: {
development.child4 = _null;
development.child4Id = _null;
2025-01-30 08:53:02 +07:00
development.child4DnaId = _null;
development.child4ShortName = _null;
2024-04-18 14:50:49 +07:00
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
2024-04-18 14:50:49 +07:00
}
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-1
*
* @summary DEV_00 - /tab2-1 #
*
* @param {string} id Id
*/
@Put("tab2_1_add/{id}")
async CreateDevelopmenttab2_1(
@Path() id: string,
@Body() requestBody: CreatePlannedGoal,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-04-11 16:32:44 +07:00
const data = Object.assign(new PlannedGoal(), { ...requestBody, positions: [] });
2024-04-11 11:39:56 +07:00
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
data.developmentPlannedGoalId = development.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalRepository.save(data, { data: request });
2024-04-11 11:39:56 +07:00
await Promise.all(
2024-04-11 11:39:56 +07:00
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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
// }
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
_data.createdUserId = request.user.sub;
_data.createdFullName = request.user.name;
_data.lastUpdateUserId = request.user.sub;
_data.lastUpdateFullName = request.user.name;
_data.createdAt = new Date();
_data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
_data.plannedGoalId = data.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalPositionRepository.save(_data, { data: request });
setLogDataDiff(request, { before, after: development });
}),
);
2024-04-11 11:39:56 +07:00
return new HttpSuccess(data.id);
}
/**
* API /tab2-2
*
* @summary DEV_00 - /tab2-2 #
*
* @param {string} id Id
*/
@Put("tab2_2_add/{id}")
async CreateDevelopmenttab2_2(
@Path() id: string,
@Body() requestBody: CreatePlannedPeople,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
const data = Object.assign(new PlannedPeople(), requestBody);
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
data.developmentPlannedPeopleId = development.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedPeopleRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(data.id);
}
/**
* API /tab2-3
*
* @summary DEV_00 - /tab2-3 #
*
* @param {string} id Id
*/
@Put("tab2_3_add/{id}")
async CreateDevelopmenttab2_3(
@Path() id: string,
@Body() requestBody: CreateActualGoal,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
const data = Object.assign(new ActualGoal(), requestBody);
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
data.developmentActualGoalId = development.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store ActualGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.actualGoalRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(data.id);
}
/**
* API /tab2-4
*
* @summary DEV_00 - /tab2-4 #
*
* @param {string} id Id
*/
@Put("tab2_4_add/{id}")
async CreateDevelopmenttab2_4(
@Path() id: string,
2024-04-11 16:32:44 +07:00
@Body() requestBody: CreateActualPeople,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
const data = Object.assign(new ActualPeople(), requestBody);
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
data.developmentActualPeopleId = development.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store ActualPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.actualPeopleRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(data.id);
}
/**
* API /tab2-1
*
* @summary DEV_00 - /tab2-1 #
*
2024-04-11 16:32:44 +07:00
* @param {string} id Id
2024-04-11 11:39:56 +07:00
*/
@Put("tab2_1_edit/{id}")
async UpdateDevelopmenttab2_1(
@Path() id: string,
@Body() requestBody: CreatePlannedGoal,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.plannedGoalRepository.findOne({
where: { id },
relations: {
plannedGoalPositions: true,
},
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in the field on the PlannedGoalPosition.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions, {
data: request,
});
2024-04-11 16:32:44 +07:00
Object.assign(development, { ...requestBody, positions: [] });
2024-04-11 11:39:56 +07:00
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store PlannedGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
if (requestBody.positions != null) {
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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
// }
2024-04-11 11:39:56 +07:00
_data.createdUserId = request.user.sub;
_data.createdFullName = request.user.name;
_data.lastUpdateUserId = request.user.sub;
_data.lastUpdateFullName = request.user.name;
_data.createdAt = new Date();
_data.lastUpdatedAt = new Date();
2024-04-11 11:39:56 +07:00
_data.plannedGoalId = development.id;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Planned Goal Position.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalPositionRepository.save(_data, {
data: {
request: request,
},
});
2024-04-11 11:39:56 +07:00
}),
);
}
return new HttpSuccess(development.id);
}
/**
* API /tab2-2
*
* @summary DEV_00 - /tab2-2 #
*
2024-04-11 16:32:44 +07:00
* @param {string} id Id
2024-04-11 11:39:56 +07:00
*/
@Put("tab2_2_edit/{id}")
async UpdateDevelopmenttab2_2(
@Path() id: string,
@Body() requestBody: CreatePlannedPeople,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.plannedPeopleRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store PlannedPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedPeopleRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-3
*
* @summary DEV_00 - /tab2-3 #
*
2024-04-11 16:32:44 +07:00
* @param {string} id Id
2024-04-11 11:39:56 +07:00
*/
@Put("tab2_3_edit/{id}")
async UpdateDevelopmenttab2_3(
@Path() id: string,
@Body() requestBody: CreateActualGoal,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.actualGoalRepository.findOne({
where: { id },
});
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, "ไม่พบข้อมูลระดับตำแหน่ง");
// }
// }
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store ActualGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.actualGoalRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-4
*
* @summary DEV_00 - /tab2-4 #
*
2024-04-11 16:32:44 +07:00
* @param {string} id Id
2024-04-11 11:39:56 +07:00
*/
@Put("tab2_4_edit/{id}")
async UpdateDevelopmenttab2_4(
@Path() id: string,
@Body() requestBody: CreateActualPeople,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-07-25 17:06:42 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.actualPeopleRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store ActualPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.actualPeopleRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-1
*
* @summary DEV_00 - /tab2-1 #
*
* @param {string} id Id
*/
@Delete("tab2_1/{id}")
2024-07-25 17:06:42 +07:00
async DeleteDevelopmenttab2_1(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.plannedGoalRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามแผน");
}
const _development = await this.plannedGoalPositionRepository.find({
where: { plannedGoalId: id },
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in PlannedGoalPosition.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalPositionRepository.remove(_development, { data: request });
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in PlannedGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalRepository.remove(development, { data: request });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-2
*
* @summary DEV_00 - /tab2-2 #
*
* @param {string} id Id
*/
@Delete("tab2_2/{id}")
2024-07-25 17:06:42 +07:00
async DeleteDevelopmenttab2_2(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.plannedPeopleRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
}
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in PlannedPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedPeopleRepository.remove(development, { data: request });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-3
*
* @summary DEV_00 - /tab2-3 #
*
* @param {string} id Id
*/
@Delete("tab2_3/{id}")
2024-07-25 17:06:42 +07:00
async DeleteDevelopmenttab2_3(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.actualGoalRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง");
}
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in ActualGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.actualGoalRepository.remove(development, { data: request });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab2-4
*
* @summary DEV_00 - /tab2-4 #
*
* @param {string} id Id
*/
@Delete("tab2_4/{id}")
2024-07-25 17:06:42 +07:00
async DeleteDevelopmenttab2_4(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.actualPeopleRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง");
}
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove data in ActualPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.actualPeopleRepository.remove(development, { data: request });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API / tab3
*
* @summary DEV_00 - / tab3 #
*
* @param {string} id Id
*/
@Put("tab3/{id}")
async UpdateDevelopmentTab3(
@Path() id: string,
@Body() requestBody: UpdateDevelopment3,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
relations: {
developmentProjectTypes: true,
2024-04-11 16:32:44 +07:00
developmentProjectTechniquePlanneds: true,
developmentProjectTechniqueActuals: true,
2024-08-22 14:14:35 +07:00
developmentAddresss: true,
2024-04-11 11:39:56 +07:00
},
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-04-11 16:32:44 +07:00
Object.assign(development, {
...requestBody,
developmentProjectTypes: [],
developmentProjectTechniquePlanneds: [],
developmentProjectTechniqueActuals: [],
2024-08-22 14:14:35 +07:00
developmentAddresss: [],
2024-04-11 16:32:44 +07:00
});
2024-04-11 11:39:56 +07:00
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
2024-07-25 17:06:42 +07:00
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, {
data: request,
});
2024-04-11 16:32:44 +07:00
await this.developmentProjectTechniquePlannedRepository.remove(
development.developmentProjectTechniquePlanneds,
2024-07-25 17:06:42 +07:00
{
data: request,
2024-07-30 16:49:16 +07:00
},
2024-04-11 16:32:44 +07:00
);
await this.developmentProjectTechniqueActualRepository.remove(
development.developmentProjectTechniqueActuals,
2024-07-25 17:06:42 +07:00
{
data: request,
2024-07-30 16:49:16 +07:00
},
2024-04-11 11:39:56 +07:00
);
2024-04-17 15:27:37 +07:00
const _null: any = null;
if (
requestBody.strategyChildPlannedNode != undefined &&
requestBody.strategyChildPlannedNode != null
) {
switch (requestBody.strategyChildPlannedNode) {
case 1: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildPlannedId) {
const checkId = await this.strategyChild1Repository.findOne({
where: { id: requestBody.strategyChildPlannedId },
});
if (!checkId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผนระดับ 1",
);
}
development.strategyChild1PlannedId = checkId.id;
development.strategyChild2PlannedId = _null;
development.strategyChild3PlannedId = _null;
development.strategyChild4PlannedId = _null;
development.strategyChild5PlannedId = _null;
2024-04-17 15:27:37 +07:00
}
break;
}
case 2: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildPlannedId) {
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.strategyChild3PlannedId = _null;
development.strategyChild4PlannedId = _null;
development.strategyChild5PlannedId = _null;
2024-04-17 15:27:37 +07:00
}
break;
}
case 3: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildPlannedId) {
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.strategyChild4PlannedId = _null;
development.strategyChild5PlannedId = _null;
2024-04-17 15:27:37 +07:00
}
break;
}
case 4: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildPlannedId) {
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.strategyChild5PlannedId = _null;
2024-04-17 15:27:37 +07:00
}
break;
}
case 5: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildPlannedId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน");
}
}
if (
requestBody.strategyChildActualNode != undefined &&
requestBody.strategyChildActualNode != null
) {
switch (requestBody.strategyChildActualNode) {
case 1: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildActualId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
case 2: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildActualId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
case 3: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildActualId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
case 4: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildActualId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
case 5: {
2024-04-17 17:04:37 +07:00
if (requestBody.strategyChildActualId) {
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;
2024-04-17 15:27:37 +07:00
}
break;
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง");
}
}
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-07-25 17:06:42 +07:00
await this.developmentRepository.save(development, { data: request });
2024-04-18 13:51:34 +07:00
if (requestBody.developmentProjectTypes != null) {
await Promise.all(
requestBody.developmentProjectTypes.map(async (x) => {
let data = new DevelopmentProjectType();
data.name = x;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-18 13:51:34 +07:00
data.developmentId = development.id;
2024-07-25 17:06:42 +07:00
await this.developmentProjectTypeRepository.save(data, { data: request });
2024-04-18 13:51:34 +07:00
}),
);
}
if (requestBody.developmentProjectTechniquePlanneds != null) {
await Promise.all(
requestBody.developmentProjectTechniquePlanneds.map(async (x) => {
let data = new DevelopmentProjectTechniquePlanned();
data.name = x;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-18 13:51:34 +07:00
data.developmentId = development.id;
2024-07-25 17:06:42 +07:00
await this.developmentProjectTechniquePlannedRepository.save(data, { data: request });
2024-04-18 13:51:34 +07:00
}),
);
}
if (requestBody.developmentProjectTechniqueActuals != null) {
await Promise.all(
requestBody.developmentProjectTechniqueActuals.map(async (x) => {
let data = new DevelopmentProjectTechniquePlanned();
data.name = x;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-18 13:51:34 +07:00
data.developmentId = development.id;
2024-07-25 17:06:42 +07:00
await this.developmentProjectTechniqueActualRepository.save(data, { data: request });
2024-04-18 13:51:34 +07:00
}),
);
}
2024-08-07 14:03:40 +07:00
//move from tab5
2024-08-07 18:15:55 +07:00
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
data: request,
});
2024-08-22 14:14:35 +07:00
2024-08-08 13:27:23 +07:00
// const before = structuredClone(development);
2024-08-07 18:15:55 +07:00
await Promise.all(
requestBody.developmentAddresss.map(async (x) => {
const data = Object.assign(new DevelopmentAddress(), x);
2024-08-08 15:28:29 +07:00
if (x.address) {
2025-01-17 17:52:13 +07:00
await new CallAPI()
.GetData(request, `/org/metadata/province/${x.provinceId}`)
.then(async (item) => {
data.provinceName = item.name;
})
.catch(async (x) => {});
2024-08-08 15:28:29 +07:00
data.developmentId = development.id;
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-08-08 15:28:29 +07:00
await this.developmentAddresssRepository.save(data, { data: request });
}
2024-08-08 13:27:23 +07:00
// setLogDataDiff(request, { before, after: development });
2024-08-07 18:15:55 +07:00
}),
2024-08-07 14:03:40 +07:00
);
2024-08-22 14:14:35 +07:00
2024-08-07 14:03:40 +07:00
//End
2024-04-11 11:39:56 +07:00
return new HttpSuccess(development.id);
}
/**
* API / tab4
*
* @summary DEV_00 - / tab4 #
*
* @param {string} id Id
*/
@Put("tab4/{id}")
async UpdateDevelopmentTab4(
@Path() id: string,
@Body() requestBody: UpdateDevelopment4,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 11:39:56 +07:00
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-07-25 17:06:42 +07:00
await this.developmentRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 16:32:44 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab4-1
*
* @summary DEV_00 - /tab4-1 #
*
* @param {string} id Id
*/
@Put("tab4_1_add/{id}")
async CreateDevelopmenttab4_1(
@Path() id: string,
@Body() requestBody: CreateDevelopmentEvaluation,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 16:32:44 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-11 16:32:44 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-08-22 14:14:35 +07:00
let results: any =
requestBody.results && requestBody.results != "" ? requestBody.results : null;
2024-07-25 17:06:42 +07:00
const before = structuredClone(development);
2024-04-11 16:32:44 +07:00
const data = Object.assign(new DevelopmentEvaluation(), requestBody);
2024-08-08 14:56:11 +07:00
data.results = results;
data.createdUserId = request.user.sub;
2024-04-11 16:32:44 +07:00
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-04-11 16:32:44 +07:00
data.developmentId = development.id;
2024-07-25 17:06:42 +07:00
await this.developmentEvaluationRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
2024-04-11 16:32:44 +07:00
return new HttpSuccess(data.id);
}
/**
* API /tab4-1
*
* @summary DEV_00 - /tab4-1 #
*
* @param {string} id Id
*/
@Delete("tab4_1/{id}")
2024-07-25 17:06:42 +07:00
async DeleteDevelopmenttab4_1(@Path() id: string, @Request() request: RequestWithUser) {
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Get Development Evaluation By ID.",
// });
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-04-11 16:32:44 +07:00
const development = await this.developmentEvaluationRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
}
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove Development Evaluation By ID.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentEvaluationRepository.remove(development, { data: request });
2024-04-11 16:32:44 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab4-1
*
* @summary DEV_00 - /tab4-1 #
*
* @param {string} id Id
*/
@Put("tab4_1_edit/{id}")
async UpdateDevelopmenttab4_1(
@Path() id: string,
@Body() requestBody: CreateDevelopmentEvaluation,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 16:32:44 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-04-11 16:32:44 +07:00
const development = await this.developmentEvaluationRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentEvaluation.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentEvaluationRepository.save(development, { data: request });
2024-04-02 17:53:45 +07:00
return new HttpSuccess(development.id);
}
/**
2024-04-11 11:39:56 +07:00
* API / tab5
2024-04-02 17:53:45 +07:00
*
2024-04-11 11:39:56 +07:00
* @summary DEV_00 - / tab5 #
2024-04-02 17:53:45 +07:00
*
* @param {string} id Id
*/
2024-04-11 11:39:56 +07:00
@Put("tab5/{id}")
async UpdateDevelopmentTab5(
2024-04-02 17:53:45 +07:00
@Path() id: string,
2024-04-11 11:39:56 +07:00
@Body() requestBody: UpdateDevelopment5,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-02 17:53:45 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
const development = await this.developmentRepository.findOne({
where: { id },
2024-04-11 16:32:44 +07:00
relations: { developmentAddresss: true },
});
2024-04-02 17:53:45 +07:00
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-08-08 11:27:28 +07:00
Object.assign(development, { ...requestBody, developmentAddresss: [] });
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-08 11:27:28 +07:00
await this.developmentRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API /tab5-1
*
* @summary DEV_00 - /tab5-1 #
*
* @param {string} id Id
*/
@Put("tab5_1_add/{id}")
async CreateDevelopmenttab5_1(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentOther,
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-08-08 11:27:28 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const before = structuredClone(development);
const data = Object.assign(new DevelopmentOther(), requestBody);
2025-01-17 17:52:13 +07:00
await new CallAPI()
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
.then(async (item) => {
data.provinceActualName = item.name;
})
.catch(async (x) => {});
2024-08-08 11:27:28 +07:00
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-08-08 11:27:28 +07:00
data.developmentId = development.id;
await this.developmentOtherRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(data.id);
}
/**
* API /tab5-1
*
* @summary DEV_00 - /tab5-1 #
*
* @param {string} id Id
*/
@Delete("tab5_1/{id}")
async DeleteDevelopmenttab5_1(@Path() id: string, @Request() request: RequestWithUser) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-08-08 11:27:28 +07:00
const development = await this.developmentOtherRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
}
await this.developmentOtherRepository.remove(development, { data: request });
return new HttpSuccess(development.id);
}
/**
* API /tab5-1
*
* @summary DEV_00 - /tab5-1 #
*
* @param {string} id Id
*/
@Put("tab5_1_edit/{id}")
async UpdateDevelopmenttab5_1(
@Path() id: string,
@Body() requestBody: UpdateDevelopmentOther,
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-08-08 11:27:28 +07:00
const development = await this.developmentOtherRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
}
Object.assign(development, requestBody);
2025-01-17 17:52:13 +07:00
await new CallAPI()
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
.then(async (item) => {
development.provinceActualName = item.name;
})
.catch(async (x) => {});
2024-04-02 17:53:45 +07:00
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-08 11:27:28 +07:00
await this.developmentOtherRepository.save(development, { data: request });
2024-08-07 14:03:40 +07:00
return new HttpSuccess(development.id);
}
2024-08-07 18:15:55 +07:00
/**
2024-08-07 14:03:40 +07:00
* API / tab7
*
* @summary DEV_00 - / tab7 #
*
* @param {string} id Id
*/
@Put("tab7/{id}")
async UpdateDevelopmentTab7(
@Path() id: string,
@Body() requestBody: UpdateDevelopment7,
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-08-07 14:03:40 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
relations: { developmentAddresss: true },
2024-07-25 17:06:42 +07:00
});
2024-08-07 14:03:40 +07:00
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
Object.assign(development, { ...requestBody });
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-07 14:03:40 +07:00
await this.developmentRepository.save(development, { data: request });
return new HttpSuccess(development.id);
}
2024-08-07 17:34:44 +07:00
2024-08-07 15:08:40 +07:00
/**
2024-08-07 17:34:44 +07:00
* API / tab7
2024-08-07 15:08:40 +07:00
*
2024-08-07 17:34:44 +07:00
* @summary DEV_00 - /tab7 #
2024-08-07 15:08:40 +07:00
*
* @param {string} id Id
*/
@Get("tab7/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab7ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-08-07 15:08:40 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id },
});
const _getDevelopment = {
id: getDevelopment ? getDevelopment.id : null,
accept: getDevelopment ? getDevelopment.accept : null,
receive: getDevelopment ? getDevelopment.receive : null,
approved: getDevelopment ? getDevelopment.approved : null,
budget: getDevelopment ? getDevelopment.budget : null,
budgetSub: getDevelopment ? getDevelopment.budgetSub : null,
budgetPay: getDevelopment ? getDevelopment.budgetPay : null,
};
return new HttpSuccess(_getDevelopment);
}
2024-04-11 16:32:44 +07:00
2024-08-07 18:15:55 +07:00
/**
2024-08-07 17:34:44 +07:00
* API / tab8
*
* @summary DEV_00 - /tab8 #
*
* @param {string} id Id
*/
@Get("tab8/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab8ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-08-07 17:34:44 +07:00
const getDevelopment = await this.developmentRepository.findOne({
relations: ["developmentRisks"],
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
let _getDevelopment = {
developmentRisks:
getDevelopment.developmentRisks == null
? null
: getDevelopment.developmentRisks.sort((a, b) =>
2024-08-22 14:14:35 +07:00
(a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(
b.createdAt.toString() == null ? "" : b.createdAt.toString(),
),
2024-08-07 17:34:44 +07:00
),
expect: getDevelopment.expect,
};
return new HttpSuccess(_getDevelopment);
}
2024-08-07 18:15:55 +07:00
/**
2024-08-07 14:03:40 +07:00
* API / tab8
*
* @summary DEV_00 - / tab8 #
*
* @param {string} id Id
*/
@Put("tab8/{id}")
async UpdateDevelopmentTab8(
@Path() id: string,
@Body() requestBody: UpdateDevelopment8,
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-08-07 14:03:40 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
relations: { developmentAddresss: true },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
Object.assign(development, { ...requestBody });
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-07 14:03:40 +07:00
await this.developmentRepository.save(development, { data: request });
2024-04-02 17:53:45 +07:00
return new HttpSuccess(development.id);
}
2024-08-07 17:34:44 +07:00
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Put("tab8_1_add/{id}")
async CreateDevelopmenttab8_1(
@Path() id: string,
2024-08-07 18:15:55 +07:00
@Body() requestBody: UpdateDevelopmentRisk,
2024-08-07 17:34:44 +07:00
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-08-07 17:34:44 +07:00
const development = await this.developmentRepository.findOne({
where: { id },
});
if (!development) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const before = structuredClone(development);
2024-08-07 18:15:55 +07:00
const data = Object.assign(new DevelopmentRisk(), requestBody);
2024-08-07 17:34:44 +07:00
data.createdUserId = request.user.sub;
data.createdFullName = request.user.name;
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.createdAt = new Date();
data.lastUpdatedAt = new Date();
2024-08-07 17:34:44 +07:00
data.developmentId = development.id;
2024-08-07 18:15:55 +07:00
await this.developmentRiskRepository.save(data, { data: request });
2024-08-07 17:34:44 +07:00
setLogDataDiff(request, { before, after: development });
return new HttpSuccess(data.id);
}
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Delete("tab8_1/{id}")
async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
2024-08-07 18:15:55 +07:00
const development = await this.developmentRiskRepository.findOne({
2024-08-07 17:34:44 +07:00
where: { id },
});
if (!development) {
2024-08-07 18:15:55 +07:00
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
2024-08-07 17:34:44 +07:00
}
2024-08-07 18:15:55 +07:00
await this.developmentRiskRepository.remove(development, { data: request });
2024-08-07 17:34:44 +07:00
return new HttpSuccess(development.id);
}
/**
* API /tab8-1
*
* @summary DEV_00 - /tab8-1 #
*
* @param {string} id Id
*/
@Put("tab8_1_edit/{id}")
async UpdateDevelopmenttab8_1(
@Path() id: string,
2024-08-07 18:15:55 +07:00
@Body() requestBody: UpdateDevelopmentRisk,
2024-08-07 17:34:44 +07:00
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
2024-08-07 18:15:55 +07:00
const development = await this.developmentRiskRepository.findOne({
2024-08-07 17:34:44 +07:00
where: { id },
});
if (!development) {
2024-08-07 18:15:55 +07:00
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
2024-08-07 17:34:44 +07:00
}
Object.assign(development, requestBody);
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.lastUpdatedAt = new Date();
2024-08-07 18:15:55 +07:00
await this.developmentRiskRepository.save(development, { data: request });
2024-08-07 17:34:44 +07:00
return new HttpSuccess(development.id);
}
2024-04-02 17:53:45 +07:00
2024-04-03 14:54:56 +07:00
/**
* API
*
* @summary DEV_00 - #
*
*/
@Get("search")
async ListDevelopemt(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query() searchField?: "year" | "projectName",
@Query() searchKeyword: string = "",
) {
let queryLike = "development.projectName LIKE :keyword";
2024-04-03 14:54:56 +07:00
if (searchField == "year") {
queryLike = "development.year LIKE :keyword";
2024-04-03 14:54:56 +07:00
}
const [record, total] = await this.developmentRepository
.createQueryBuilder("development")
2024-04-03 14:54:56 +07:00
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = await Promise.all(
record.map((_data) => {
return {
id: _data.id,
year: _data.year,
projectName: _data.projectName,
dateStart: _data.dateStart,
dateEnd: _data.dateEnd,
totalDate: _data.totalDate,
addressAcademic: _data.addressAcademic,
topicAcademic: _data.topicAcademic,
};
}),
);
return new HttpSuccess({ data: data, total });
}
/**
* API /
*
* @summary DEV_004 - /
*
*/
@Get("done")
async GetDevelopmentListsDone(@Query("year") year: number) {
const [development, total] = await AppDataSource.getRepository(Development)
.createQueryBuilder("development")
.andWhere(year > 0 ? "development.year LIKE :year" : "1=1", {
year: `${year.toString()}`,
})
.andWhere("development.status LIKE :status", {
status: `%FINISH%`,
})
.select(["development.id", "development.projectName", "development.year"])
.orderBy("development.year", "DESC")
2024-11-28 17:49:15 +07:00
.addOrderBy("development.createdAt", "DESC")
.getManyAndCount();
return new HttpSuccess({ data: development, total });
}
2024-04-02 17:53:45 +07:00
/**
* API /
*
* @summary DEV_003 - / #3
*
2024-04-11 16:32:44 +07:00
* @param {string} id Id
2024-04-02 17:53:45 +07:00
*/
@Delete("{id}")
2024-07-30 16:49:16 +07:00
async DeleteDevelopment(@Path() id: string, @Request() request: RequestWithUser) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
const development = await this.developmentRepository.findOne({
where: { id },
relations: {
developmentActualPeoples: true,
developmentPlannedPeoples: true,
developmentActualGoals: true,
developmentPlannedGoals: true,
2024-04-11 11:39:56 +07:00
developmentProjectTypes: true,
2024-04-11 16:32:44 +07:00
developmentProjectTechniquePlanneds: true,
developmentProjectTechniqueActuals: true,
2024-04-11 11:39:56 +07:00
developmentEvaluations: true,
developmentAddresss: true,
},
});
if (!development) {
2024-04-02 17:53:45 +07:00
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
if (
development.developmentPlannedGoals != null &&
development.developmentPlannedGoals.length > 0
) {
const plannedGoalPosition = await this.plannedGoalPositionRepository.find({
where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) },
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove PlannedGoalPosition.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request });
}
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove ActualPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.actualPeopleRepository.remove(development.developmentActualPeoples, {
data: request,
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove PlannedPeople.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, {
data: request,
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove ActualGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request });
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove PlannedGoal.",
// });
2024-07-25 17:06:42 +07:00
await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request });
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove DevelopmentProjectType.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, {
data: request,
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove DevelopmentProjectTechniquePlanned.",
// });
2024-04-11 16:32:44 +07:00
await this.developmentProjectTechniquePlannedRepository.remove(
development.developmentProjectTechniquePlanneds,
2024-07-25 17:06:42 +07:00
{
data: request,
},
2024-04-11 16:32:44 +07:00
);
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove DevelopmentProjectTechniqueActuals.",
// });
2024-04-11 16:32:44 +07:00
await this.developmentProjectTechniqueActualRepository.remove(
development.developmentProjectTechniqueActuals,
2024-07-25 17:06:42 +07:00
{
data: request,
},
2024-04-11 11:39:56 +07:00
);
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove DevelopmentEvaluation.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentEvaluationRepository.remove(development.developmentEvaluations, {
data: request,
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove DevelopmentAddresss.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
data: request,
});
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "remove",
// status: "success",
// description: "Remove Development.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentRepository.remove(development, { data: request });
2024-04-02 17:53:45 +07:00
return new HttpSuccess();
}
/**
* API /
*
* @summary DEV_004 - / #4
*
*/
@Get()
async GetDevelopmentLists(
2024-08-22 14:14:35 +07:00
@Request() request: RequestWithUser,
2024-04-02 17:53:45 +07:00
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
2024-04-03 17:32:11 +07:00
@Query("year") year: number,
2024-04-11 11:39:56 +07:00
@Query("status") status: string,
@Query("nodeId") nodeId?: string | null,
@Query("node") node?: number | null,
2024-04-02 17:53:45 +07:00
@Query("keyword") keyword?: string,
) {
2024-09-03 11:44:57 +07:00
// await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP");
2024-04-02 17:53:45 +07:00
const [development, total] = await AppDataSource.getRepository(Development)
.createQueryBuilder("development")
2024-04-03 17:32:11 +07:00
.andWhere(year > 0 ? "development.year LIKE :year" : "1=1", {
year: `${year.toString()}`,
})
.andWhere(
node != undefined && node != null
? node == 4
2025-01-30 08:53:02 +07:00
? "development.child4DnaId LIKE :nodeId"
: node == 3
2025-01-30 08:53:02 +07:00
? "development.child3DnaId LIKE :nodeId"
: node == 2
2025-01-30 08:53:02 +07:00
? "development.child2DnaId LIKE :nodeId"
: node == 1
2025-01-30 08:53:02 +07:00
? "development.child1DnaId LIKE :nodeId"
: "development.rootDnaId LIKE :nodeId"
: "1=1",
{
nodeId: `${nodeId}`,
},
)
2024-04-11 11:39:56 +07:00
.andWhere(status != undefined ? "development.status LIKE :status" : "1=1", {
status: `%${status}%`,
})
2024-12-19 13:26:30 +07:00
.andWhere(
keyword != undefined
2024-12-26 22:17:57 +07:00
? new Brackets((qb) => {
2024-12-19 13:26:30 +07:00
qb.where("development.projectName LIKE :keyword")
.orWhere("development.root LIKE :keyword")
.orWhere("development.child1 LIKE :keyword")
.orWhere("development.child2 LIKE :keyword")
.orWhere("development.child3 LIKE :keyword")
.orWhere("development.child4 LIKE :keyword");
})
: "1=1",
{
keyword: `%${keyword}%`,
},
)
.select([
"development.id",
"development.projectName",
"development.year",
"development.root",
"development.child1",
"development.child2",
"development.child3",
"development.child4",
])
2024-04-02 17:53:45 +07:00
.orderBy("development.year", "DESC")
2024-11-28 17:49:15 +07:00
.addOrderBy("development.createdAt", "DESC")
2024-04-02 17:53:45 +07:00
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: development, total });
}
/**
2024-04-11 11:39:56 +07:00
* API
*
* @summary DEV_00 - #
*
* @param {string} id Id
*/
@Get("finish/{id}")
2024-07-25 17:06:42 +07:00
async FinishDevelopemtById(@Path() id: string, @Request() request: RequestWithUser) {
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
getDevelopment.status = "FINISH";
getDevelopment.lastUpdateUserId = request.user.sub;
getDevelopment.lastUpdateFullName = request.user.name;
getDevelopment.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store Development.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentRepository.save(getDevelopment, { data: request });
2024-04-11 11:39:56 +07:00
return new HttpSuccess(getDevelopment);
}
/**
* API
*
* @summary DEV_00 - #
*
* @param {string} id Id
*/
@Get("status/{id}")
async StatusDevelopemtById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
select: ["id", "status"],
});
return new HttpSuccess(getDevelopment);
}
/**
* API / tab1
*
* @summary DEV_00 - /tab1 #
*
* @param {string} id Id
*/
@Get("tab1/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab1ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
let node = null;
let nodeId = null;
2025-02-03 14:45:35 +07:00
let nodeDnaId = null;
if (getDevelopment.child4Id != null) {
node = 4;
nodeId = getDevelopment.child4Id;
2025-02-03 14:45:35 +07:00
nodeDnaId = getDevelopment.child4DnaId;
} else if (getDevelopment.child3Id != null) {
node = 3;
nodeId = getDevelopment.child3Id;
2025-02-03 14:45:35 +07:00
nodeDnaId = getDevelopment.child3DnaId;
} else if (getDevelopment.child2Id != null) {
node = 2;
nodeId = getDevelopment.child2Id;
2025-02-03 14:45:35 +07:00
nodeDnaId = getDevelopment.child2DnaId;
} else if (getDevelopment.child1Id != null) {
node = 1;
nodeId = getDevelopment.child1Id;
2025-02-03 14:45:35 +07:00
nodeDnaId = getDevelopment.child1DnaId;
} else if (getDevelopment.rootId != null) {
node = 0;
nodeId = getDevelopment.rootId;
2025-02-03 14:45:35 +07:00
nodeDnaId = getDevelopment.rootDnaId;
}
const formattedData = {
id: getDevelopment.id,
2024-04-26 16:07:09 +07:00
revisionId: getDevelopment.orgRevisionId,
year: getDevelopment.year,
projectName: getDevelopment.projectName,
reason: getDevelopment.reason,
objective: getDevelopment.objective,
node: node,
nodeId: nodeId,
2025-02-03 14:45:35 +07:00
nodeDnaId: nodeDnaId,
2024-04-26 10:18:20 +07:00
root: getDevelopment.rootId,
child1: getDevelopment.child1Id,
child2: getDevelopment.child2Id,
child3: getDevelopment.child3Id,
child4: getDevelopment.child4Id,
2025-02-03 14:45:35 +07:00
rootDna: getDevelopment.rootDnaId,
child1Dna: getDevelopment.child1DnaId,
child2Dna: getDevelopment.child2DnaId,
child3Dna: getDevelopment.child3DnaId,
child4Dna: getDevelopment.child4DnaId,
};
return new HttpSuccess(formattedData);
2024-04-11 11:39:56 +07:00
}
/**
* API / tab2
*
* @summary DEV_00 - /tab2 #
*
* @param {string} id Id
*/
@Get("tab2/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab2ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
//posTypeActual
2024-04-11 11:39:56 +07:00
relations: [
"developmentActualPeoples",
"developmentPlannedPeoples",
"developmentActualGoals",
// "developmentActualGoals.posTypeActual",
// "developmentActualGoals.posLevelActual",
"developmentActualGoals",
2024-04-11 11:39:56 +07:00
"developmentPlannedGoals",
"developmentPlannedGoals.plannedGoalPositions",
// "developmentPlannedGoals.plannedGoalPositions.posTypePlanned",
// "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned",
2024-04-11 11:39:56 +07:00
],
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
let _getDevelopment: any = {
id: getDevelopment.id,
2024-04-11 16:32:44 +07:00
actualPeoples:
getDevelopment.developmentActualPeoples == null
? null
: getDevelopment.developmentActualPeoples.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
plannedPeoples:
getDevelopment.developmentPlannedPeoples == null
? null
: getDevelopment.developmentPlannedPeoples.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
),
actualGoals:
getDevelopment.developmentActualGoals == null
? null
: getDevelopment.developmentActualGoals
.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
)
.map((x) => ({
2024-04-17 17:04:37 +07:00
id: x.id,
groupTarget: x.groupTarget,
groupTargetSub: x.groupTargetSub,
position: x.position,
// posTypeId: x.posTypeActualId,
// posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName,
// posLevelId: x.posLevelActualId,
// posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName,
posType: x.posTypeActual,
posLevel: x.posLevelActual,
type: x.type,
amount: x.amount,
})),
2024-04-11 16:32:44 +07:00
plannedGoals:
getDevelopment.developmentPlannedGoals == null
? null
: getDevelopment.developmentPlannedGoals
.sort((a, b) =>
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
b.groupTarget == null ? "" : b.groupTarget,
),
)
.map((x) => ({
2024-04-17 17:04:37 +07:00
id: x.id,
groupTarget: x.groupTarget,
groupTargetSub: x.groupTargetSub,
2024-04-17 15:27:37 +07:00
type: x.type,
position: x.plannedGoalPositions.map((y) => ({
2024-04-17 17:04:37 +07:00
id: y.id,
position: y.position,
2025-03-14 15:32:17 +07:00
posExecutive: y.posExecutive,
// posTypeId: y.posTypePlannedId,
// posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName,
// posLevelId: y.posLevelPlannedId,
// posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName,
posType: y.posTypePlanned,
posLevel: y.posLevelPlanned,
})),
amount: x.amount,
})),
2024-04-11 11:39:56 +07:00
};
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab3
*
* @summary DEV_00 - /tab3 #
*
* @param {string} id Id
*/
@Get("tab3/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab3ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
relations: [
2024-04-11 16:32:44 +07:00
"developmentProjectTypes",
"developmentProjectTechniquePlanneds",
"developmentProjectTechniqueActuals",
2024-08-08 13:27:23 +07:00
"developmentAddresss",
2024-04-11 11:39:56 +07:00
],
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-04-11 16:32:44 +07:00
let _getDevelopment: any = {
developmentProjectTypes: getDevelopment.developmentProjectTypes.map((x) => x.name).sort(),
projectModalActual: getDevelopment.projectModalActual,
projectModalPlanned: getDevelopment.projectModalPlanned,
2024-04-11 16:32:44 +07:00
isBackPlanned: getDevelopment.isBackPlanned,
isHoldPlanned: getDevelopment.isHoldPlanned,
projectDayBackPlanned: getDevelopment.projectDayBackPlanned,
projectDayHoldPlanned: getDevelopment.projectDayHoldPlanned,
projectNigthHoldPlanned: getDevelopment.projectNigthHoldPlanned,
developmentProjectTechniquePlanneds: getDevelopment.developmentProjectTechniquePlanneds
.map((x) => x.name)
.sort(),
isBackActual: getDevelopment.isBackActual,
isHoldActual: getDevelopment.isHoldActual,
projectDayBackActual: getDevelopment.projectDayBackActual,
projectDayHoldActual: getDevelopment.projectDayHoldActual,
projectNigthHoldActual: getDevelopment.projectNigthHoldActual,
reasonActual70: getDevelopment.reasonActual70,
reasonActual20: getDevelopment.reasonActual20,
reasonActual10: getDevelopment.reasonActual10,
2024-10-01 10:31:25 +07:00
isReasonActual70: getDevelopment.isReasonActual70,
isReasonActual20: getDevelopment.isReasonActual20,
isReasonActual10: getDevelopment.isReasonActual10,
reasonPlanned70: getDevelopment.reasonPlanned70,
reasonPlanned20: getDevelopment.reasonPlanned20,
reasonPlanned10: getDevelopment.reasonPlanned10,
2024-10-01 10:31:25 +07:00
isReasonPlanned70: getDevelopment.isReasonPlanned70,
isReasonPlanned20: getDevelopment.isReasonPlanned20,
isReasonPlanned10: getDevelopment.isReasonPlanned10,
2024-04-11 16:32:44 +07:00
developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals
.map((x) => x.name)
.sort(),
2024-04-17 15:37:14 +07:00
strategyChild1Planned: getDevelopment.strategyChild1PlannedId,
strategyChild2Planned: getDevelopment.strategyChild2PlannedId,
strategyChild3Planned: getDevelopment.strategyChild3PlannedId,
strategyChild4Planned: getDevelopment.strategyChild4PlannedId,
strategyChild5Planned: getDevelopment.strategyChild5PlannedId,
strategyChild1Actual: getDevelopment.strategyChild1ActualId,
strategyChild2Actual: getDevelopment.strategyChild2ActualId,
strategyChild3Actual: getDevelopment.strategyChild3ActualId,
strategyChild4Actual: getDevelopment.strategyChild4ActualId,
strategyChild5Actual: getDevelopment.strategyChild5ActualId,
2024-08-08 14:04:14 +07:00
dateStart: getDevelopment.dateStart,
dateEnd: getDevelopment.dateEnd,
totalDate: getDevelopment.totalDate,
2024-08-08 13:27:23 +07:00
developmentAddresss:
2024-08-22 14:14:35 +07:00
getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss,
2024-04-11 16:32:44 +07:00
};
2024-04-11 11:39:56 +07:00
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab3
*
* @summary DEV_00 - /tab3 #
*
* @param {string} id Id
*/
@Get("tab3_1/{id}")
async GetDevelopemtTab3_1ById(@Path() id: string) {
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
relations: [
"developmentProjectTypes",
"developmentProjectTechniquePlanneds",
"developmentProjectTechniqueActuals",
],
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
let _getDevelopment: any = {
projectModalActual: getDevelopment.projectModalActual,
isBackActual: getDevelopment.isBackActual,
isHoldActual: getDevelopment.isHoldActual,
projectDayBackActual: getDevelopment.projectDayBackActual,
projectDayHoldActual: getDevelopment.projectDayHoldActual,
projectNigthHoldActual: getDevelopment.projectNigthHoldActual,
reasonActual70: getDevelopment.reasonActual70,
reasonActual20: getDevelopment.reasonActual20,
reasonActual10: getDevelopment.reasonActual10,
2024-10-01 10:31:25 +07:00
isReasonActual70: getDevelopment.isReasonActual70,
isReasonActual20: getDevelopment.isReasonActual20,
isReasonActual10: getDevelopment.isReasonActual10,
developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals
.map((x) => x.name)
.sort(),
strategyChild1Actual: getDevelopment.strategyChild1ActualId,
strategyChild2Actual: getDevelopment.strategyChild2ActualId,
strategyChild3Actual: getDevelopment.strategyChild3ActualId,
strategyChild4Actual: getDevelopment.strategyChild4ActualId,
strategyChild5Actual: getDevelopment.strategyChild5ActualId,
};
return new HttpSuccess(_getDevelopment);
}
2024-04-11 11:39:56 +07:00
/**
* API / tab4
*
* @summary DEV_00 - /tab4 #
*
* @param {string} id Id
*/
@Get("tab4/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab4ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
2024-04-11 16:32:44 +07:00
relations: ["developmentEvaluations"],
2024-04-11 11:39:56 +07:00
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-04-11 16:32:44 +07:00
let _getDevelopment = {
developmentEvaluations:
getDevelopment.developmentEvaluations == null
? null
: getDevelopment.developmentEvaluations.sort((a, b) =>
(a.indicators == null ? "" : a.indicators).localeCompare(
b.indicators == null ? "" : b.indicators,
),
),
2024-08-08 10:39:44 +07:00
progressTracking: getDevelopment.progressTracking,
projectEvaluation: getDevelopment.projectEvaluation,
2024-04-11 16:32:44 +07:00
};
2024-04-11 11:39:56 +07:00
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab5
*
* @summary DEV_00 - /tab5 #
*
* @param {string} id Id
*/
@Get("tab5/{id}")
2024-08-22 14:14:35 +07:00
async GetDevelopemtTab5ById(@Request() request: RequestWithUser, @Path() id: string) {
2024-10-22 08:21:07 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
2024-08-08 11:27:28 +07:00
relations: ["developmentOthers"],
2024-04-11 11:39:56 +07:00
where: { id: id },
});
2024-08-22 14:14:35 +07:00
if (!getDevelopment) {
2024-04-11 11:39:56 +07:00
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
2024-08-22 14:14:35 +07:00
let _getDevelopment = {
2024-08-08 11:27:28 +07:00
developmentOthers:
getDevelopment.developmentOthers == null
2024-04-11 16:32:44 +07:00
? null
2024-08-08 11:27:28 +07:00
: getDevelopment.developmentOthers.sort((a, b) =>
2024-08-22 14:14:35 +07:00
(a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(
b.createdAt.toString() == null ? "" : b.createdAt.toString(),
),
2024-04-11 16:32:44 +07:00
),
2024-08-08 11:27:28 +07:00
obstacle: getDevelopment.obstacle,
suggestion: getDevelopment.suggestion,
2024-08-08 11:52:15 +07:00
project: getDevelopment.project,
2024-08-08 11:27:28 +07:00
isPassAllocate: getDevelopment.isPassAllocate,
2024-08-08 11:52:15 +07:00
isPassNoAllocate: getDevelopment.isPassNoAllocate,
2024-08-08 11:27:28 +07:00
isNoPass: getDevelopment.isNoPass,
isBudget: getDevelopment.isBudget,
isOutBudget: getDevelopment.isOutBudget,
2024-04-11 16:32:44 +07:00
};
2024-08-08 11:27:28 +07:00
2024-04-11 11:39:56 +07:00
return new HttpSuccess(_getDevelopment);
}
/**
* API / tab6
2024-04-02 17:53:45 +07:00
*
2024-04-11 11:39:56 +07:00
* @summary DEV_00 - /tab6 #
2024-04-02 17:53:45 +07:00
*
* @param {string} id Id
*/
2024-04-11 11:39:56 +07:00
@Get("tab6/{id}")
async GetDevelopemtTab6ById(@Path() id: string) {
const getDevelopment = await this.developmentHistoryRepository.find({
where: { developmentId: id },
relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"],
order: {
isDone: "ASC",
2024-10-01 00:41:09 +07:00
isDoneIDP: "ASC",
citizenId: "ASC",
},
2024-04-02 17:53:45 +07:00
});
const _getDevelopment = getDevelopment.map((item) => ({
id: item.id,
type: item.type,
idcard: item.citizenId,
fullName: item.prefix + item.firstName + " " + item.lastName,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
posTypeName:
item.type == "OFFICER"
? item.posType
? item.posType.posTypeName
: null
: item.employeePosType
? item.employeePosType.posTypeName
: null,
posLevelName:
item.type == "OFFICER"
? item.posLevel
? item.posLevel.posLevelName
: null
: item.employeePosLevel
? `${item.employeePosType.posTypeShortName ?? ""} ${item.employeePosLevel.posLevelName ?? ""}`
: null,
posExecutive: item.posExecutive,
2024-04-17 17:31:07 +07:00
org: item.org,
trainingDays: item.trainingDays,
commandNumber: item.order,
commandDate: item.dateOrder,
dateStart: item.dateStart,
dateEnd: item.dateEnd,
isDone: item.isDone,
2024-10-01 00:41:09 +07:00
isDoneIDP: item.isDoneIDP,
2024-07-30 11:33:46 +07:00
isProfile: item.isProfile,
}));
2024-04-03 16:14:00 +07:00
return new HttpSuccess(_getDevelopment);
2024-04-02 17:53:45 +07:00
}
2024-04-11 11:39:56 +07:00
/**
* API / tab6
*
* @summary DEV_00 - /tab6 #
*
* @param {string} id Id
*/
@Get("tab6/done/{id}")
2024-07-25 17:06:42 +07:00
async GetDevelopemtTab6DoneById(@Path() id: string, @Request() request: RequestWithUser) {
const getDevelopment = await this.developmentHistoryRepository.find({
2024-05-21 18:17:47 +07:00
where: { developmentId: id, isDone: false },
relations: ["development"],
});
await Promise.all(
getDevelopment.map(async (x) => {
const _data = Object.assign(new DevelopmentHistory(), x);
2024-05-21 18:17:47 +07:00
if (x.type == "OFFICER") {
await new CallAPI()
2024-07-10 10:45:01 +07:00
.PostData(request, "/org/profile/training", {
profileId: x.profileId,
name: x.development == null ? null : x.development.projectName,
topic: x.development == null ? null : x.development.topicAcademic,
yearly: x.development == null ? null : x.development.year,
place: x.development == null ? null : x.development.addressAcademic,
duration: x.trainingDays,
department: x.development == null ? null : x.development.root,
numberOrder: x.order,
dateOrder: x.dateOrder,
startDate: x.dateStart,
endDate: x.dateEnd,
isDate: true,
})
.then((x) => {
_data.isDone = true;
})
.catch((x) => {
_data.isDone = false;
});
2024-05-21 18:17:47 +07:00
} else if (x.type == "EMPLOYEE") {
await new CallAPI()
2024-07-10 10:45:01 +07:00
.PostData(request, "/org/profile-employee/training", {
profileEmployeeId: x.profileId,
name: x.development == null ? null : x.development.projectName,
topic: x.development == null ? null : x.development.topicAcademic,
yearly: x.development == null ? null : x.development.year,
place: x.development == null ? null : x.development.addressAcademic,
duration: x.trainingDays,
department: x.development == null ? null : x.development.root,
numberOrder: x.order,
dateOrder: x.dateOrder,
startDate: x.dateStart,
endDate: x.dateEnd,
isDate: true,
})
.then((x) => {
_data.isDone = true;
})
.catch((x) => {
_data.isDone = false;
});
}
_data.lastUpdateUserId = request.user.sub;
_data.lastUpdateFullName = request.user.name;
_data.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentHistoryRepository.save(_data, { data: request });
}),
);
return new HttpSuccess(getDevelopment);
}
2024-10-01 00:41:09 +07:00
/**
* API / tab6 IDP
*
* @summary DEV_00 - /tab6 IDP #
*
* @param {string} id Id
*/
@Get("tab6/done-idp/{id}")
async GetDevelopemtTab6IDPDoneById(@Path() id: string, @Request() request: RequestWithUser) {
const getDevelopment = await this.developmentHistoryRepository.find({
where: { developmentId: id, isDoneIDP: false },
2024-10-01 01:14:18 +07:00
relations: ["development", "development.developmentProjectTechniqueActuals"],
2024-10-01 00:41:09 +07:00
});
let isDevelopment70: boolean = false
const dev70Lists = [
"on_the_job_training",
"job_project_assignment",
"job_shadowing",
"job_enlargement",
"internal_trainer",
"rotation",
"activity",
"site_visit",
"benchmarking",
"problem_solving",
"team_working",
"other1"
];
let isDevelopment20: boolean = false
const dev20Lists = [
"coaching",
"mentoring",
"team_meeting",
"consulting",
"feedback",
"other2"
];
let isDevelopment10: boolean = false
const dev10Lists = [
"self_learning",
"classroom_training",
"in_house_training",
"public_training",
"e_training",
"meeting",
"seminar",
"other3"
];
2024-10-01 00:41:09 +07:00
await Promise.all(
getDevelopment.map(async (x) => {
const _data = Object.assign(new DevelopmentHistory(), x);
const techniqueActuals = x.development?.developmentProjectTechniqueActuals.flatMap(x => x.name) || [];
isDevelopment70 = techniqueActuals.length > 0 && dev70Lists.some(item => techniqueActuals.includes(item));
isDevelopment20 = techniqueActuals.length > 0 && dev20Lists.some(item => techniqueActuals.includes(item));
isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some(item => techniqueActuals.includes(item));
2024-10-01 00:41:09 +07:00
if (x.type == "OFFICER") {
await new CallAPI()
.PostData(request, "/org/profile/development", {
type: "DEVELOP",
profileId: x.profileId,
2024-10-01 10:31:25 +07:00
name: x.development.projectName,
achievement10: null,
achievement5: null,
achievement0: null,
2024-10-01 00:41:09 +07:00
kpiDevelopmentId: x.development.id,
reasonDevelopment70: x.development.reasonActual70,
reasonDevelopment20: x.development.reasonActual20,
reasonDevelopment10: x.development.reasonActual10,
isDevelopment70: isDevelopment70,
isDevelopment20: isDevelopment20,
isDevelopment10: isDevelopment10,
2024-10-01 10:31:25 +07:00
developmentTarget: null,
developmentResults: null,
developmentReport: null,
2024-10-01 01:14:18 +07:00
developmentProjects: x.development.developmentProjectTechniqueActuals.map(
(x) => x.name,
),
2024-10-01 00:41:09 +07:00
})
.then((x) => {
_data.isDoneIDP = true;
})
.catch((x) => {
_data.isDoneIDP = false;
});
} else if (x.type == "EMPLOYEE") {
await new CallAPI()
.PostData(request, "/org/profile-employee/development", {
type: "DEVELOP",
profileEmployeeId: x.profileId,
2024-10-01 10:31:25 +07:00
name: x.development.projectName,
achievement10: null,
achievement5: null,
achievement0: null,
2024-10-01 00:41:09 +07:00
kpiDevelopmentId: x.development.id,
reasonDevelopment70: x.development.reasonActual70,
reasonDevelopment20: x.development.reasonActual20,
reasonDevelopment10: x.development.reasonActual10,
isDevelopment70: isDevelopment70,
isDevelopment20: isDevelopment20,
isDevelopment10: isDevelopment10,
2024-10-01 10:31:25 +07:00
developmentTarget: null,
developmentResults: null,
developmentReport: null,
2024-10-01 01:14:18 +07:00
developmentProjects: x.development.developmentProjectTechniqueActuals.map(
(x) => x.name,
),
2024-10-01 00:41:09 +07:00
})
.then((x) => {
_data.isDoneIDP = true;
})
.catch((x) => {
_data.isDoneIDP = false;
});
}
_data.lastUpdateUserId = request.user.sub;
_data.lastUpdateFullName = request.user.name;
_data.lastUpdatedAt = new Date();
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
await this.developmentHistoryRepository.save(_data, { data: request });
}),
);
return new HttpSuccess(getDevelopment);
}
/**
* API list
*
* @summary DEV_00 - list #
*
*/
@Get("org/root")
2024-07-25 17:06:42 +07:00
async GetOrgDevelopemt() {
const getOrg = await this.developmentRepository
.createQueryBuilder("development")
.select("development.root")
.groupBy("development.root")
.getRawMany();
if (getOrg.length > 0) {
return new HttpSuccess(getOrg.map((x) => x.development_root));
}
return new HttpSuccess(getOrg);
}
@Get("registry/{type}/{developmentId}")
async developmentDetail(
@Path() developmentId: string,
@Path() type: string,
2024-12-26 22:17:57 +07:00
@Request() request: RequestWithUser,
) {
const getDevelopment = await this.developmentRepository.findOne({
where: { id: developmentId },
relations: [
"developmentProjectTypes",
"developmentProjectTechniquePlanneds",
"developmentProjectTechniqueActuals",
"developmentAddresss",
],
});
if (!getDevelopment)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
if (type.trim().toLocaleUpperCase() == "OFFICER") {
2024-12-26 22:17:57 +07:00
let _workflow = await new permission().Workflow(
request,
developmentId,
"SYS_REGISTRY_OFFICER",
);
if (_workflow == false) await new permission().PermissionGet(request, "SYS_REGISTRY_OFFICER");
} else if (type.trim().toLocaleUpperCase() == "USER") {
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเข้าถึงข้อมูลนี้ได้");
}
2024-12-26 22:17:57 +07:00
let _getDevelopment: any = {
id: getDevelopment.id,
evaluationId: null,
target: null,
summary: null,
point: null,
name: getDevelopment.projectName,
2024-12-19 17:32:00 +07:00
achievement10: "มีผลการพัฒนาและมีการดำเนินการตามเป้าหมายการนำไปพัฒนางาน",
achievement5: "มีผลการพัฒนาแต่ยังไม่ได้ดำเนินการตามเป้าหมายการนำไปพัฒนางาน",
achievement0: "ไม่ได้ดำเนินการพัฒนา",
isDevelopment70: getDevelopment.isReasonActual70,
isDevelopment20: getDevelopment.isReasonActual20,
isDevelopment10: getDevelopment.isReasonActual10,
reasonDevelopment70: getDevelopment.reasonActual70,
reasonDevelopment20: getDevelopment.reasonActual20,
reasonDevelopment10: getDevelopment.reasonActual10,
selectType: "PROJECT",
selectTypeYear: getDevelopment.year,
selectTypeId: null,
2024-12-26 22:17:57 +07:00
developmentProjects: getDevelopment.developmentProjectTechniqueActuals
.map((x) => x.name)
.sort(),
};
return new HttpSuccess(_getDevelopment);
}
2024-04-11 11:39:56 +07:00
/**
* API upload User
*
* @summary DEV_0 - upload User #
*
* @param {string} id Id
*/
@Post("tab6/{id}")
@UseInterceptors(FileInterceptor("file"))
2024-04-11 11:39:56 +07:00
async UploadUserDevelopemtById(
@Path() id: string,
@UploadedFile() file: Express.Multer.File,
2024-07-25 17:06:42 +07:00
@Request() request: RequestWithUser,
2024-04-11 11:39:56 +07:00
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-04-11 11:39:56 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
relations: {
developmentHistorys: true,
},
2024-04-11 11:39:56 +07:00
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const workbook = xlsx.read(file.buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0]; // Assuming we're reading the first sheet
const sheet = workbook.Sheets[sheetName];
const getDevelopments = xlsx.utils.sheet_to_json(sheet);
2024-07-26 16:30:38 +07:00
const before = null;
await Promise.all(
getDevelopments.map(async (item: any) => {
if (item["รหัสประจำตัวประชาชน"] == undefined || item["รหัสประจำตัวประชาชน"].length != 13)
return;
2024-04-30 14:14:51 +07:00
const oldProfile: any = getDevelopment.developmentHistorys.find(
(x) => x.citizenId == item["รหัสประจำตัวประชาชน"],
);
2024-04-30 13:19:44 +07:00
if (oldProfile != null) {
if (oldProfile.isDone == true) return;
}
if (item["ประเภท"] == undefined) return;
2024-12-26 22:17:57 +07:00
let development = Object.assign(new DevelopmentHistory(), oldProfile);
if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ" || item["ประเภท"] == "ขรก.กทม. สามัญ") {
await new CallAPI()
2024-07-10 10:45:01 +07:00
.GetData(request, `/org/unauthorize/officer/citizen/${item["รหัสประจำตัวประชาชน"]}`)
.then(async (x: any) => {
2024-12-26 22:17:57 +07:00
development = Object.assign(development, x);
development.dateStart =
item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"];
development.dateEnd =
item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"];
development.order =
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
? null
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
development.dateOrder =
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
? null
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
development.trainingDays =
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
2024-04-30 13:19:44 +07:00
development.posLevelId = x.posLevelId;
development.posTypeId = x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = true;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
2024-07-26 16:30:38 +07:00
setLogDataDiff(request, { before, after: development });
})
2024-07-30 16:49:16 +07:00
.catch(async (x) => {
let _null: any = null;
development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"];
development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"];
development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"];
development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"];
development.org = item["สังกัด"] == undefined ? null : item["สังกัด"];
development.dateStart =
item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"];
development.dateEnd =
item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"];
2024-07-31 09:55:56 +07:00
development.citizenId =
item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"];
2024-07-31 10:15:24 +07:00
development.type = "OFFICER" == undefined ? _null : "OFFICER";
2024-07-30 16:49:16 +07:00
development.order =
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
? null
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
development.dateOrder =
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
? _null
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
development.trainingDays =
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
development.posLevelId = x.posLevelId;
development.posTypeId = x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = false;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
});
} else if (item["ประเภท"] == "ลูกจ้างประจำ") {
await new CallAPI()
2024-12-26 23:05:35 +07:00
.GetData(request, `/org/unauthorize/employee/citizen/${item["รหัสประจำตัวประชาชน"]}`)
.then(async (x: any) => {
2024-12-26 22:17:57 +07:00
development = Object.assign(development, x);
development.dateStart =
item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"];
development.dateEnd =
item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"];
development.order =
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
? null
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
development.dateOrder =
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
? null
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
development.trainingDays =
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
development.posLevelId = null;
development.posTypeId = null;
development.employeePosLevelId = x.posLevelId;
development.employeePosTypeId = x.posTypeId;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = true;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-25 17:06:42 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
2024-07-26 16:30:38 +07:00
setLogDataDiff(request, { before, after: development });
})
2024-07-30 16:49:16 +07:00
.catch(async (x) => {
let _null: any = null;
development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"];
development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"];
development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"];
development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"];
development.org = item["สังกัด"] == undefined ? null : item["สังกัด"];
development.dateStart =
item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"];
development.dateEnd =
item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"];
2024-07-31 09:55:56 +07:00
development.citizenId =
item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"];
2024-07-31 10:15:24 +07:00
development.type = "EMPLOYEE" == undefined ? _null : "EMPLOYEE";
2024-07-30 16:49:16 +07:00
development.order =
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
? null
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
development.dateOrder =
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
? _null
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
development.trainingDays =
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
development.posLevelId = x.posLevelId;
development.posTypeId = x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = false;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
});
} else {
let development = new DevelopmentHistory();
let _null: any = null;
development.prefix = item["คำนำหน้า"] == undefined ? null : item["คำนำหน้า"];
development.firstName = item["ชื่อ"] == undefined ? null : item["ชื่อ"];
development.lastName = item["นามสกุล"] == undefined ? null : item["นามสกุล"];
development.position = item["ตำแหน่ง"] == undefined ? null : item["ตำแหน่ง"];
development.org = item["สังกัด"] == undefined ? null : item["สังกัด"];
development.dateStart =
item["วันที่เริ่มต้น"] == undefined ? null : item["วันที่เริ่มต้น"];
development.dateEnd = item["วันที่สิ้นสุด"] == undefined ? null : item["วันที่สิ้นสุด"];
development.citizenId =
item["รหัสประจำตัวประชาชน"] == undefined ? _null : item["รหัสประจำตัวประชาชน"];
development.type = "OTHER";
development.order =
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == undefined
? null
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"];
development.dateOrder =
item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"] == undefined
? _null
: new Date(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]);
development.trainingDays =
item["จำนวนวันที่อบรม"] == undefined ? null : item["จำนวนวันที่อบรม"];
development.posLevelId = null;
development.posTypeId = null;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
development.isProfile = false;
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
}
}),
);
return new HttpSuccess(getDevelopments);
2024-04-11 11:39:56 +07:00
}
2024-07-30 16:49:16 +07:00
/**
* API upload User One by one
*
* @summary DEV_0 - upload User One by one #
*
* @param {string} id Id
*/
@Post("uploadUser/{id}")
async UploadUserDevelopemtOBO(
@Path() id: string,
@Body() requestBody: CreateDevelopmentHistoryOBO,
@Request() request: RequestWithUser,
) {
2024-08-09 17:08:28 +07:00
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
2024-07-30 16:49:16 +07:00
const getDevelopment = await this.developmentRepository.findOne({
where: { id: id },
relations: {
developmentHistorys: true,
},
});
if (!getDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
}
const oldProfile: any = await this.developmentHistoryRepository.findOne({
where: { citizenId: requestBody.citizenId },
});
const before = null;
let status = null;
let _null: any = null;
if (oldProfile != null) {
if (oldProfile.isDone == true)
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ข้อมูลนี้ได้ถูกบันทึกแล้ว");
oldProfile.dateStart = requestBody.dateStart == undefined ? _null : requestBody.dateStart;
oldProfile.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd;
2024-07-30 17:23:45 +07:00
oldProfile.order = requestBody.commandNumber == undefined ? _null : requestBody.commandNumber;
2024-07-30 16:49:16 +07:00
oldProfile.dateOrder =
2024-07-30 17:23:45 +07:00
requestBody.commandDate == undefined ? _null : new Date(requestBody.commandDate);
2024-07-30 16:49:16 +07:00
oldProfile.trainingDays =
requestBody.trainingDays == undefined ? _null : requestBody.trainingDays;
oldProfile.createdUserId = request.user.sub;
oldProfile.createdFullName = request.user.name;
oldProfile.lastUpdateUserId = request.user.sub;
oldProfile.lastUpdateFullName = request.user.name;
oldProfile.createdAt = new Date();
oldProfile.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(oldProfile, { data: request });
setLogDataDiff(request, { before, after: oldProfile });
status = oldProfile.isProfile;
}
2024-07-30 17:49:37 +07:00
2024-07-30 16:49:16 +07:00
if (requestBody.type == "OFFICER") {
await new CallAPI()
.GetData(request, `/org/unauthorize/officer/citizen/${requestBody.citizenId}`)
.then(async (x: any) => {
let development = Object.assign(new DevelopmentHistory(), x);
development.dateStart =
requestBody.dateStart == undefined ? _null : requestBody.dateStart;
development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd;
2024-07-30 17:49:37 +07:00
development.order =
requestBody.commandNumber == undefined ? _null : requestBody.commandNumber;
2024-07-30 16:49:16 +07:00
development.dateOrder =
2024-07-30 17:23:45 +07:00
requestBody.commandDate == undefined ? _null : requestBody.commandDate;
2024-07-30 16:49:16 +07:00
development.trainingDays =
requestBody.trainingDays == undefined ? _null : requestBody.trainingDays;
development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId;
development.posTypeId = x.posTypeId == undefined ? _null : x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.isProfile = true;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
status = development.isProfile;
})
.catch(async (x) => {
let development = new DevelopmentHistory();
let _null: any = null;
development.prefix = requestBody.prefix == undefined ? _null : requestBody.prefix;
development.firstName =
requestBody.firstName == undefined ? _null : requestBody.firstName;
development.lastName = requestBody.lastName == undefined ? _null : requestBody.lastName;
development.position = requestBody.position == undefined ? _null : requestBody.position;
development.org = requestBody.org == undefined ? _null : requestBody.org;
development.dateStart =
requestBody.dateStart == undefined ? _null : requestBody.dateStart;
development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd;
2024-07-30 17:49:37 +07:00
development.citizenId =
requestBody.citizenId == undefined ? _null : requestBody.citizenId;
development.type = requestBody.type == undefined ? _null : requestBody.type;
development.order =
requestBody.commandNumber == undefined ? _null : requestBody.commandNumber;
2024-07-30 16:49:16 +07:00
development.dateOrder =
2024-07-30 17:23:45 +07:00
requestBody.commandDate == undefined ? _null : requestBody.commandDate;
2024-07-30 16:49:16 +07:00
development.trainingDays =
requestBody.trainingDays == undefined ? _null : requestBody.trainingDays;
development.posLevelId = x.posLevelId == undefined ? _null : x.posLevelId;
development.posTypeId = x.posTypeId == undefined ? _null : x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = false;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
status = development.isProfile;
});
} else {
await new CallAPI()
.GetData(request, `/org/unauthorize/employee/citizen/${requestBody.citizenId}`)
.then(async (x: any) => {
let development = Object.assign(new DevelopmentHistory(), x);
development.dateStart =
requestBody.dateStart == undefined ? _null : requestBody.dateStart;
development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd;
2024-07-30 17:49:37 +07:00
development.order =
requestBody.commandNumber == undefined ? _null : requestBody.commandNumber;
2024-07-30 16:49:16 +07:00
development.dateOrder =
2024-07-30 17:23:45 +07:00
requestBody.commandDate == undefined ? _null : requestBody.commandDate;
2024-07-30 16:49:16 +07:00
development.trainingDays =
requestBody.trainingDays == undefined ? _null : requestBody.trainingDays;
development.posLevelId = null;
development.posTypeId = null;
development.employeePosLevelId = x.posLevelId;
development.employeePosTypeId = x.posTypeId;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = true;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
status = development.isProfile;
})
.catch(async (x) => {
let development = new DevelopmentHistory();
let _null: any = null;
development.prefix = requestBody.prefix == undefined ? _null : requestBody.prefix;
development.firstName =
requestBody.firstName == undefined ? _null : requestBody.firstName;
development.lastName = requestBody.lastName == undefined ? _null : requestBody.lastName;
development.position = requestBody.position == undefined ? _null : requestBody.position;
development.org = requestBody.org == undefined ? _null : requestBody.org;
development.dateStart =
requestBody.dateStart == undefined ? _null : requestBody.dateStart;
development.dateEnd = requestBody.dateEnd == undefined ? _null : requestBody.dateEnd;
2024-07-30 17:49:37 +07:00
development.citizenId =
requestBody.citizenId == undefined ? _null : requestBody.citizenId;
development.type = requestBody.type == undefined ? _null : requestBody.type;
development.order =
requestBody.commandNumber == undefined ? _null : requestBody.commandNumber;
development.dateOrder =
requestBody.commandDate == undefined ? _null : requestBody.commandDate;
2024-07-30 16:49:16 +07:00
development.trainingDays =
requestBody.trainingDays == undefined ? _null : requestBody.trainingDays;
development.posLevelId = x.posLevelId;
development.posTypeId = x.posTypeId;
development.employeePosLevelId = null;
development.employeePosTypeId = null;
development.developmentId = id;
development.createdUserId = request.user.sub;
development.createdFullName = request.user.name;
development.lastUpdateUserId = request.user.sub;
development.lastUpdateFullName = request.user.name;
development.createdAt = new Date();
development.lastUpdatedAt = new Date();
2024-07-30 16:49:16 +07:00
development.isProfile = false;
2024-08-01 14:31:32 +07:00
// addLogSequence(request, {
// action: "database",
// status: "success",
// description: "Store DevelopmentHistory.",
// });
2024-07-30 16:49:16 +07:00
await this.developmentHistoryRepository.save(development, { data: request });
setLogDataDiff(request, { before, after: development });
status = development.isProfile;
});
}
2024-07-30 17:49:37 +07:00
return new HttpSuccess(status);
2024-07-30 16:49:16 +07:00
}
2024-04-02 17:53:45 +07:00
}