3412 lines
144 KiB
TypeScript
3412 lines
144 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Route,
|
|
Security,
|
|
Tags,
|
|
Body,
|
|
Path,
|
|
Request,
|
|
Query,
|
|
UploadedFile,
|
|
// Extension,
|
|
} from "tsoa";
|
|
import { AppDataSource } from "../database/data-source";
|
|
import { In, Not } from "typeorm";
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
import HttpError from "../interfaces/http-error";
|
|
import HttpStatusCode from "../interfaces/http-status";
|
|
import {
|
|
Development,
|
|
CreateDevelopment,
|
|
UpdateDevelopment1,
|
|
UpdateDevelopment3,
|
|
UpdateDevelopment4,
|
|
UpdateDevelopment5,
|
|
UpdateDevelopment7,
|
|
UpdateDevelopment8,
|
|
} 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";
|
|
import { DevelopmentProjectType } from "../entities/DevelopmentProjectType";
|
|
import {
|
|
CreateDevelopmentEvaluation,
|
|
DevelopmentEvaluation,
|
|
} from "../entities/DevelopmentEvaluation";
|
|
import { DevelopmentAddress } from "../entities/DevelopmentAddress";
|
|
import { DevelopmentProjectTechniquePlanned } from "../entities/DevelopmentProjectTechniquePlanned";
|
|
import { DevelopmentProjectTechniqueActual } from "../entities/DevelopmentProjectTechniqueActual";
|
|
import { StrategyChild1 } from "../entities/StrategyChild1";
|
|
import { StrategyChild2 } from "../entities/StrategyChild2";
|
|
import { StrategyChild3 } from "../entities/StrategyChild3";
|
|
import { StrategyChild4 } from "../entities/StrategyChild4";
|
|
import { StrategyChild5 } from "../entities/StrategyChild5";
|
|
import CallAPI from "../interfaces/call-api";
|
|
import { UseInterceptors } from "@nestjs/common";
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
import * as xlsx from "xlsx";
|
|
import { setLogDataDiff } from "../interfaces/utils";
|
|
import { RequestWithUser } from "../middlewares/user";
|
|
import { DevelopmentRisk, UpdateDevelopmentRisk } from "../entities/DevelopmentRisk";
|
|
import { DevelopmentOther, UpdateDevelopmentOther } from "../entities/DevelopmentOther";
|
|
import permission from "../interfaces/permission";
|
|
import { Brackets } from "typeorm";
|
|
import Extension from "../interfaces/extension";
|
|
@Route("api/v1/development/main")
|
|
@Tags("Development")
|
|
@Security("bearerAuth")
|
|
export class DevelopmentController extends Controller {
|
|
private developmentRepository = AppDataSource.getRepository(Development);
|
|
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
|
|
private developmentOtherRepository = AppDataSource.getRepository(DevelopmentOther);
|
|
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
|
|
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
|
|
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
|
|
private developmentProjectTechniquePlannedRepository = AppDataSource.getRepository(
|
|
DevelopmentProjectTechniquePlanned,
|
|
);
|
|
private developmentProjectTechniqueActualRepository = AppDataSource.getRepository(
|
|
DevelopmentProjectTechniqueActual,
|
|
);
|
|
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);
|
|
|
|
/**
|
|
* API ล้างข้อมูล
|
|
*
|
|
* @summary ล้างข้อมูล
|
|
*
|
|
*/
|
|
@Get("clear-db")
|
|
async ClearDb() {
|
|
return new HttpSuccess();
|
|
}
|
|
|
|
/**
|
|
* API เพิ่มโครงการ/หลักสูตรการฝึกอบรม
|
|
*
|
|
* @summary DEV_001 - เพิ่มโครงการ/หลักสูตรการฝึกอบรม#1
|
|
*
|
|
*/
|
|
@Post()
|
|
async CreateDevelopment(
|
|
@Body() requestBody: CreateDevelopment,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
const chk_name = await this.developmentRepository.find({
|
|
where: {
|
|
projectName: requestBody.projectName,
|
|
year: requestBody.year,
|
|
},
|
|
});
|
|
if (chk_name.length > 0) {
|
|
throw new HttpError(
|
|
HttpStatusCode.NOT_FOUND,
|
|
"โครงการ/หลักสูตรการฝึกอบรม: " +
|
|
requestBody.projectName +
|
|
" ปีงบประมาณ: " +
|
|
(requestBody.year + 543) +
|
|
" มีอยู่ในระบบแล้ว",
|
|
);
|
|
}
|
|
|
|
const development = Object.assign(new Development(), requestBody);
|
|
await new CallAPI()
|
|
.PostData(request, "/org/find/all", {
|
|
node: requestBody.node,
|
|
nodeId: requestBody.nodeId,
|
|
})
|
|
.then((x) => {
|
|
development.root = x.root;
|
|
development.rootId = x.rootId;
|
|
development.rootDnaId = x.rootDnaId;
|
|
development.rootShortName = x.rootShortName;
|
|
development.child1 = x.child1;
|
|
development.child1Id = x.child1Id;
|
|
development.child1DnaId = x.child1DnaId;
|
|
development.child1ShortName = x.child1ShortName;
|
|
development.child2 = x.child2;
|
|
development.child2Id = x.child2Id;
|
|
development.child2DnaId = x.child2DnaId;
|
|
development.child2ShortName = x.child2ShortName;
|
|
development.child3 = x.child3;
|
|
development.child3Id = x.child3Id;
|
|
development.child3DnaId = x.child3DnaId;
|
|
development.child3ShortName = x.child3ShortName;
|
|
development.child4 = x.child4;
|
|
development.child4Id = x.child4Id;
|
|
development.child4DnaId = x.child4DnaId;
|
|
development.child4ShortName = x.child4ShortName;
|
|
})
|
|
.catch((error) => {
|
|
console.error("Error calling API:", error);
|
|
});
|
|
|
|
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();
|
|
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
const before = null;
|
|
|
|
await this.developmentRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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) +
|
|
" มีอยู่ในระบบแล้ว",
|
|
);
|
|
}
|
|
const before = structuredClone(development);
|
|
Object.assign(development, requestBody);
|
|
await new CallAPI()
|
|
.PostData(request, "/org/find/all", {
|
|
node: requestBody.node,
|
|
nodeId: requestBody.nodeId,
|
|
})
|
|
.then((x) => {
|
|
development.root = x.root;
|
|
development.rootId = x.rootId;
|
|
development.rootDnaId = x.rootDnaId;
|
|
development.rootShortName = x.rootShortName;
|
|
development.child1 = x.child1;
|
|
development.child1Id = x.child1Id;
|
|
development.child1DnaId = x.child1DnaId;
|
|
development.child1ShortName = x.child1ShortName;
|
|
development.child2 = x.child2;
|
|
development.child2Id = x.child2Id;
|
|
development.child2DnaId = x.child2DnaId;
|
|
development.child2ShortName = x.child2ShortName;
|
|
development.child3 = x.child3;
|
|
development.child3Id = x.child3Id;
|
|
development.child3DnaId = x.child3DnaId;
|
|
development.child3ShortName = x.child3ShortName;
|
|
development.child4 = x.child4;
|
|
development.child4Id = x.child4Id;
|
|
development.child4DnaId = x.child4DnaId;
|
|
development.child4ShortName = x.child4ShortName;
|
|
})
|
|
.catch((x) => {});
|
|
const _null: any = null;
|
|
switch (requestBody.node) {
|
|
case 0: {
|
|
development.child1 = _null;
|
|
development.child1Id = _null;
|
|
development.child1DnaId = _null;
|
|
development.child1ShortName = _null;
|
|
development.child2 = _null;
|
|
development.child2Id = _null;
|
|
development.child2DnaId = _null;
|
|
development.child2ShortName = _null;
|
|
development.child3 = _null;
|
|
development.child3Id = _null;
|
|
development.child3DnaId = _null;
|
|
development.child3ShortName = _null;
|
|
development.child4 = _null;
|
|
development.child4Id = _null;
|
|
development.child4DnaId = _null;
|
|
development.child4ShortName = _null;
|
|
break;
|
|
}
|
|
case 1: {
|
|
development.child2 = _null;
|
|
development.child2Id = _null;
|
|
development.child2DnaId = _null;
|
|
development.child2ShortName = _null;
|
|
development.child3 = _null;
|
|
development.child3Id = _null;
|
|
development.child3DnaId = _null;
|
|
development.child3ShortName = _null;
|
|
development.child4 = _null;
|
|
development.child4Id = _null;
|
|
development.child4DnaId = _null;
|
|
development.child4ShortName = _null;
|
|
break;
|
|
}
|
|
case 2: {
|
|
development.child3 = _null;
|
|
development.child3Id = _null;
|
|
development.child3DnaId = _null;
|
|
development.child3ShortName = _null;
|
|
development.child4 = _null;
|
|
development.child4Id = _null;
|
|
development.child4DnaId = _null;
|
|
development.child4ShortName = _null;
|
|
break;
|
|
}
|
|
case 3: {
|
|
development.child4 = _null;
|
|
development.child4Id = _null;
|
|
development.child4DnaId = _null;
|
|
development.child4ShortName = _null;
|
|
break;
|
|
}
|
|
default:
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรม");
|
|
}
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
await this.developmentRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
const data = Object.assign(new PlannedGoal(), { ...requestBody, positions: [] });
|
|
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();
|
|
data.developmentPlannedGoalId = development.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
await this.plannedGoalRepository.save(data, { data: request });
|
|
|
|
await Promise.all(
|
|
requestBody.positions.map(async (x) => {
|
|
const _data = Object.assign(new PlannedGoalPosition(), x);
|
|
let checkPosType: any = null;
|
|
let posTypeShortName: any = null;
|
|
if (x.posTypePlanned) {
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" ||
|
|
requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosType = await this.empPosTypeRepository.findOne({
|
|
where: { posTypeName: x.posTypePlanned },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
|
|
}
|
|
posTypeShortName = checkPosType.posTypeShortName;
|
|
} else {
|
|
checkPosType = await this.posTypeRepository.findOne({
|
|
where: { posTypeName: x.posTypePlanned },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
if (x.posLevelPlanned) {
|
|
let checkPosLevel: any;
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" ||
|
|
requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosLevel = await this.empPosLevelRepository.find({
|
|
where: {
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
const mapShortName = checkPosLevel.flatMap(
|
|
(x: any) => `${posTypeShortName} ${x.posLevelName}`,
|
|
);
|
|
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
|
|
}
|
|
} else {
|
|
checkPosLevel = await this.posLevelRepository.findOne({
|
|
where: {
|
|
posLevelName: x.posLevelPlanned,
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
if (!checkPosLevel) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
const before = structuredClone(development);
|
|
_data.createdUserId = request.user.sub;
|
|
_data.createdFullName = request.user.name;
|
|
_data.lastUpdateUserId = request.user.sub;
|
|
_data.lastUpdateFullName = request.user.name;
|
|
_data.createdAt = new Date();
|
|
_data.lastUpdatedAt = new Date();
|
|
_data.plannedGoalId = data.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
await this.plannedGoalPositionRepository.save(_data, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
}),
|
|
);
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
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 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();
|
|
data.developmentPlannedPeopleId = development.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
await this.plannedPeopleRepository.save(data, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let checkPosType: any = null;
|
|
let posTypeShortName: any = null;
|
|
if (requestBody.posTypeActual) {
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosType = await this.empPosTypeRepository.findOne({
|
|
where: { posTypeName: requestBody.posTypeActual },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
|
|
}
|
|
posTypeShortName = checkPosType.posTypeShortName;
|
|
} else {
|
|
checkPosType = await this.posTypeRepository.findOne({
|
|
where: { posTypeName: requestBody.posTypeActual },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
if (requestBody.posLevelActual) {
|
|
let checkPosLevel: any;
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosLevel = await this.empPosLevelRepository.find({
|
|
where: {
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
const mapShortName = checkPosLevel.flatMap(
|
|
(x: any) => `${posTypeShortName} ${x.posLevelName}`,
|
|
);
|
|
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
|
|
}
|
|
} else {
|
|
checkPosLevel = await this.posLevelRepository.findOne({
|
|
where: {
|
|
posLevelName: requestBody.posLevelActual,
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
if (!checkPosLevel) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
const before = structuredClone(development);
|
|
const data = Object.assign(new ActualGoal(), requestBody);
|
|
data.createdUserId = request.user.sub;
|
|
data.createdFullName = request.user.name;
|
|
data.lastUpdateUserId = request.user.sub;
|
|
data.lastUpdateFullName = request.user.name;
|
|
data.createdAt = new Date();
|
|
data.lastUpdatedAt = new Date();
|
|
data.developmentActualGoalId = development.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store ActualGoal.",
|
|
// });
|
|
await this.actualGoalRepository.save(data, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
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,
|
|
@Body() requestBody: CreateActualPeople,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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 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();
|
|
data.developmentActualPeopleId = development.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store ActualPeople.",
|
|
// });
|
|
await this.actualPeopleRepository.save(data, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
return new HttpSuccess(data.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Put("tab2_1_edit/{id}")
|
|
async UpdateDevelopmenttab2_1(
|
|
@Path() id: string,
|
|
@Body() requestBody: CreatePlannedGoal,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.plannedGoalRepository.findOne({
|
|
where: { id },
|
|
relations: {
|
|
plannedGoalPositions: true,
|
|
},
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
const before = structuredClone(development);
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in the field on the PlannedGoalPosition.",
|
|
// });
|
|
await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions, {
|
|
data: request,
|
|
});
|
|
Object.assign(development, { ...requestBody, positions: [] });
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store PlannedGoal.",
|
|
// });
|
|
await this.plannedGoalRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
if (requestBody.positions != null) {
|
|
await Promise.all(
|
|
requestBody.positions.map(async (x) => {
|
|
const _data = Object.assign(new PlannedGoalPosition(), x);
|
|
let checkPosType: any = null;
|
|
let posTypeShortName: any = null;
|
|
if (x.posTypePlanned) {
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" ||
|
|
requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosType = await this.empPosTypeRepository.findOne({
|
|
where: { posTypeName: x.posTypePlanned },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
|
|
}
|
|
posTypeShortName = checkPosType.posTypeShortName;
|
|
} else {
|
|
checkPosType = await this.posTypeRepository.findOne({
|
|
where: { posTypeName: x.posTypePlanned },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
if (x.posLevelPlanned) {
|
|
let checkPosLevel: any;
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" ||
|
|
requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosLevel = await this.empPosLevelRepository.find({
|
|
where: {
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
const mapShortName = checkPosLevel.flatMap(
|
|
(x: any) => `${posTypeShortName} ${x.posLevelName}`,
|
|
);
|
|
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
|
|
}
|
|
} else {
|
|
checkPosLevel = await this.posLevelRepository.findOne({
|
|
where: {
|
|
posLevelName: x.posLevelPlanned,
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
if (!checkPosLevel) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
_data.createdUserId = request.user.sub;
|
|
_data.createdFullName = request.user.name;
|
|
_data.lastUpdateUserId = request.user.sub;
|
|
_data.lastUpdateFullName = request.user.name;
|
|
_data.createdAt = new Date();
|
|
_data.lastUpdatedAt = new Date();
|
|
_data.plannedGoalId = development.id;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Planned Goal Position.",
|
|
// });
|
|
await this.plannedGoalPositionRepository.save(_data, {
|
|
data: {
|
|
request: request,
|
|
},
|
|
});
|
|
}),
|
|
);
|
|
}
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Put("tab2_2_edit/{id}")
|
|
async UpdateDevelopmenttab2_2(
|
|
@Path() id: string,
|
|
@Body() requestBody: CreatePlannedPeople,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.plannedPeopleRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
const before = structuredClone(development);
|
|
Object.assign(development, requestBody);
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store PlannedPeople.",
|
|
// });
|
|
await this.plannedPeopleRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Put("tab2_3_edit/{id}")
|
|
async UpdateDevelopmenttab2_3(
|
|
@Path() id: string,
|
|
@Body() requestBody: CreateActualGoal,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.actualGoalRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let checkPosType: any = null;
|
|
let posTypeShortName: any = null;
|
|
if (requestBody.posTypeActual) {
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosType = await this.empPosTypeRepository.findOne({
|
|
where: { posTypeName: requestBody.posTypeActual },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน");
|
|
}
|
|
posTypeShortName = checkPosType.posTypeShortName;
|
|
} else {
|
|
checkPosType = await this.posTypeRepository.findOne({
|
|
where: { posTypeName: requestBody.posTypeActual },
|
|
});
|
|
if (!checkPosType) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
if (requestBody.posLevelActual) {
|
|
let checkPosLevel: any;
|
|
if (
|
|
requestBody.groupTarget == "PERSONNEL" &&
|
|
(requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP")
|
|
) {
|
|
checkPosLevel = await this.empPosLevelRepository.find({
|
|
where: {
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
const mapShortName = checkPosLevel.flatMap(
|
|
(x: any) => `${posTypeShortName} ${x.posLevelName}`,
|
|
);
|
|
if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน");
|
|
}
|
|
} else {
|
|
checkPosLevel = await this.posLevelRepository.findOne({
|
|
where: {
|
|
posLevelName: requestBody.posLevelActual,
|
|
posTypeId: checkPosType.id,
|
|
},
|
|
});
|
|
if (!checkPosLevel) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง");
|
|
}
|
|
}
|
|
}
|
|
const before = structuredClone(development);
|
|
Object.assign(development, requestBody);
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store ActualGoal.",
|
|
// });
|
|
await this.actualGoalRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Put("tab2_4_edit/{id}")
|
|
async UpdateDevelopmenttab2_4(
|
|
@Path() id: string,
|
|
@Body() requestBody: CreateActualPeople,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.actualPeopleRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
const before = structuredClone(development);
|
|
Object.assign(development, requestBody);
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store ActualPeople.",
|
|
// });
|
|
await this.actualPeopleRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1
|
|
*
|
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("tab2_1/{id}")
|
|
async DeleteDevelopmenttab2_1(@Path() id: string, @Request() request: RequestWithUser) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
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 },
|
|
});
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in PlannedGoalPosition.",
|
|
// });
|
|
await this.plannedGoalPositionRepository.remove(_development, { data: request });
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in PlannedGoal.",
|
|
// });
|
|
await this.plannedGoalRepository.remove(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2
|
|
*
|
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("tab2_2/{id}")
|
|
async DeleteDevelopmenttab2_2(@Path() id: string, @Request() request: RequestWithUser) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const development = await this.plannedPeopleRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in PlannedPeople.",
|
|
// });
|
|
await this.plannedPeopleRepository.remove(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3
|
|
*
|
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("tab2_3/{id}")
|
|
async DeleteDevelopmenttab2_3(@Path() id: string, @Request() request: RequestWithUser) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const development = await this.actualGoalRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง");
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in ActualGoal.",
|
|
// });
|
|
await this.actualGoalRepository.remove(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4
|
|
*
|
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("tab2_4/{id}")
|
|
async DeleteDevelopmenttab2_4(@Path() id: string, @Request() request: RequestWithUser) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development.",
|
|
// });
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const development = await this.actualPeopleRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง");
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove data in ActualPeople.",
|
|
// });
|
|
await this.actualPeopleRepository.remove(development, { data: request });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRepository.findOne({
|
|
where: { id },
|
|
relations: {
|
|
developmentProjectTypes: true,
|
|
developmentProjectTechniquePlanneds: true,
|
|
developmentProjectTechniqueActuals: true,
|
|
developmentAddresss: true,
|
|
},
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
Object.assign(development, {
|
|
...requestBody,
|
|
developmentProjectTypes: [],
|
|
developmentProjectTechniquePlanneds: [],
|
|
developmentProjectTechniqueActuals: [],
|
|
developmentAddresss: [],
|
|
});
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, {
|
|
data: request,
|
|
});
|
|
await this.developmentProjectTechniquePlannedRepository.remove(
|
|
development.developmentProjectTechniquePlanneds,
|
|
{
|
|
data: request,
|
|
},
|
|
);
|
|
await this.developmentProjectTechniqueActualRepository.remove(
|
|
development.developmentProjectTechniqueActuals,
|
|
{
|
|
data: request,
|
|
},
|
|
);
|
|
const _null: any = null;
|
|
if (
|
|
requestBody.strategyChildPlannedNode != undefined &&
|
|
requestBody.strategyChildPlannedNode != null
|
|
) {
|
|
switch (requestBody.strategyChildPlannedNode) {
|
|
case 1: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 2: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 3: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 4: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 5: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
|
|
default:
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามแผน");
|
|
}
|
|
}
|
|
if (
|
|
requestBody.strategyChildActualNode != undefined &&
|
|
requestBody.strategyChildActualNode != null
|
|
) {
|
|
switch (requestBody.strategyChildActualNode) {
|
|
case 1: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 2: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 3: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 4: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
case 5: {
|
|
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;
|
|
}
|
|
break;
|
|
}
|
|
|
|
default:
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์เป้าหมายตามจริง");
|
|
}
|
|
}
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
await this.developmentRepository.save(development, { data: request });
|
|
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();
|
|
data.developmentId = development.id;
|
|
await this.developmentProjectTypeRepository.save(data, { data: request });
|
|
}),
|
|
);
|
|
}
|
|
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();
|
|
data.developmentId = development.id;
|
|
await this.developmentProjectTechniquePlannedRepository.save(data, { data: request });
|
|
}),
|
|
);
|
|
}
|
|
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();
|
|
data.developmentId = development.id;
|
|
await this.developmentProjectTechniqueActualRepository.save(data, { data: request });
|
|
}),
|
|
);
|
|
}
|
|
//move from tab5
|
|
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
|
|
data: request,
|
|
});
|
|
|
|
// const before = structuredClone(development);
|
|
await Promise.all(
|
|
requestBody.developmentAddresss.map(async (x) => {
|
|
const data = Object.assign(new DevelopmentAddress(), x);
|
|
if (x.address) {
|
|
await new CallAPI()
|
|
.GetData(request, `/org/metadata/province/${x.provinceId}`)
|
|
.then(async (item) => {
|
|
data.provinceName = item.name;
|
|
})
|
|
.catch(async (x) => {});
|
|
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();
|
|
await this.developmentAddresssRepository.save(data, { data: request });
|
|
}
|
|
// setLogDataDiff(request, { before, after: development });
|
|
}),
|
|
);
|
|
|
|
//End
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
const before = structuredClone(development);
|
|
Object.assign(development, requestBody);
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
await this.developmentRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let results: any =
|
|
requestBody.results && requestBody.results != "" ? requestBody.results : null;
|
|
const before = structuredClone(development);
|
|
const data = Object.assign(new DevelopmentEvaluation(), requestBody);
|
|
data.results = results;
|
|
data.createdUserId = request.user.sub;
|
|
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();
|
|
data.developmentId = development.id;
|
|
await this.developmentEvaluationRepository.save(data, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
return new HttpSuccess(data.id);
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab4-1
|
|
*
|
|
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab4-1 #
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("tab4_1/{id}")
|
|
async DeleteDevelopmenttab4_1(@Path() id: string, @Request() request: RequestWithUser) {
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Get Development Evaluation By ID.",
|
|
// });
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentEvaluationRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "remove",
|
|
// status: "success",
|
|
// description: "Remove Development Evaluation By ID.",
|
|
// });
|
|
await this.developmentEvaluationRepository.remove(development, { data: request });
|
|
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,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentEvaluation.",
|
|
// });
|
|
await this.developmentEvaluationRepository.save(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Put("tab5/{id}")
|
|
async UpdateDevelopmentTab5(
|
|
@Path() id: string,
|
|
@Body() requestBody: UpdateDevelopment5,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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();
|
|
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,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
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);
|
|
await new CallAPI()
|
|
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
|
|
.then(async (item) => {
|
|
data.provinceActualName = item.name;
|
|
})
|
|
.catch(async (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();
|
|
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) {
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
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,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentOtherRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
|
}
|
|
Object.assign(development, requestBody);
|
|
await new CallAPI()
|
|
.GetData(request, `/org/metadata/province/${requestBody.provinceActualId}`)
|
|
.then(async (item) => {
|
|
development.provinceActualName = item.name;
|
|
})
|
|
.catch(async (x) => {});
|
|
development.lastUpdateUserId = request.user.sub;
|
|
development.lastUpdateFullName = request.user.name;
|
|
development.lastUpdatedAt = new Date();
|
|
|
|
await this.developmentOtherRepository.save(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab7 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Put("tab7/{id}")
|
|
async UpdateDevelopmentTab7(
|
|
@Path() id: string,
|
|
@Body() requestBody: UpdateDevelopment7,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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();
|
|
await this.developmentRepository.save(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab7
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab7 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab7/{id}")
|
|
async GetDevelopemtTab7ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab8/{id}")
|
|
async GetDevelopemtTab8ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
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) =>
|
|
(a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(
|
|
b.createdAt.toString() == null ? "" : b.createdAt.toString(),
|
|
),
|
|
),
|
|
expect: getDevelopment.expect,
|
|
};
|
|
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8
|
|
*
|
|
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Put("tab8/{id}")
|
|
async UpdateDevelopmentTab8(
|
|
@Path() id: string,
|
|
@Body() requestBody: UpdateDevelopment8,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
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();
|
|
await this.developmentRepository.save(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
/**
|
|
* API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1
|
|
*
|
|
* @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Put("tab8_1_add/{id}")
|
|
async CreateDevelopmenttab8_1(
|
|
@Path() id: string,
|
|
@Body() requestBody: UpdateDevelopmentRisk,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
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 DevelopmentRisk(), 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();
|
|
data.developmentId = development.id;
|
|
await this.developmentRiskRepository.save(data, { data: request });
|
|
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) {
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRiskRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!development) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความเสี่ยงของโครงการ");
|
|
}
|
|
await this.developmentRiskRepository.remove(development, { data: request });
|
|
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,
|
|
@Body() requestBody: UpdateDevelopmentRisk,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionUpdate(request, "SYS_DEV_PROJECT");
|
|
const development = await this.developmentRiskRepository.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();
|
|
|
|
await this.developmentRiskRepository.save(development, { data: request });
|
|
return new HttpSuccess(development.id);
|
|
}
|
|
|
|
/**
|
|
* 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";
|
|
if (searchField == "year") {
|
|
queryLike = "development.year LIKE :keyword";
|
|
}
|
|
const [record, total] = await this.developmentRepository
|
|
.createQueryBuilder("development")
|
|
.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")
|
|
.addOrderBy("development.createdAt", "DESC")
|
|
.getManyAndCount();
|
|
|
|
return new HttpSuccess({ data: development, total });
|
|
}
|
|
|
|
/**
|
|
* API ลบรายชื่อผู้ผ่านการอบรม
|
|
*
|
|
* @summary ลบรายชื่อผู้ผ่านการอบรม
|
|
*
|
|
* @param {string} id Id ผู้ผ่านการอบรม
|
|
*/
|
|
@Delete("delete/{id}")
|
|
async DeleteDevelopmentBy(@Path() id: string, @Request() request: RequestWithUser) {
|
|
await new permission().PermissionDelete(request, "SYS_DEV_PROJECT");
|
|
const developmentHis = await this.developmentHistoryRepository.findOne({
|
|
where: { id },
|
|
});
|
|
if (!developmentHis) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ผ่านการอบรม");
|
|
}
|
|
if (developmentHis.isProfile) {
|
|
if (developmentHis.isDone || developmentHis.isDoneIDP) {
|
|
await new CallAPI()
|
|
.PostData(request, "/org/profile/training/delete-byId", {
|
|
type: developmentHis.type,
|
|
profileId: developmentHis.profileId,
|
|
developmentId: developmentHis.developmentId,
|
|
})
|
|
.then((x) => {})
|
|
.catch((x) => {});
|
|
}
|
|
}
|
|
await this.developmentHistoryRepository.delete({ id });
|
|
return new HttpSuccess();
|
|
}
|
|
|
|
/**
|
|
* API ลบโครงการ/หลักสูตรการฝึกอบรม
|
|
*
|
|
* @summary DEV_003 - ลบโครงการ/หลักสูตรการฝึกอบรม #3
|
|
*
|
|
* @param {string} id Id รายการ
|
|
*/
|
|
@Delete("{id}")
|
|
async DeleteDevelopment(@Path() id: string, @Request() request: RequestWithUser) {
|
|
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,
|
|
developmentProjectTypes: true,
|
|
developmentProjectTechniquePlanneds: true,
|
|
developmentProjectTechniqueActuals: true,
|
|
developmentEvaluations: true,
|
|
developmentAddresss: true,
|
|
developmentRisks: true,
|
|
developmentHistorys: true,
|
|
developmentOthers: true,
|
|
},
|
|
});
|
|
if (!development) {
|
|
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)) },
|
|
});
|
|
await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request });
|
|
}
|
|
await this.actualPeopleRepository.remove(development.developmentActualPeoples, {
|
|
data: request,
|
|
});
|
|
await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, {
|
|
data: request,
|
|
});
|
|
await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request });
|
|
await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request });
|
|
await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, {
|
|
data: request,
|
|
});
|
|
await this.developmentProjectTechniquePlannedRepository.remove(
|
|
development.developmentProjectTechniquePlanneds,
|
|
{
|
|
data: request,
|
|
},
|
|
);
|
|
await this.developmentProjectTechniqueActualRepository.remove(
|
|
development.developmentProjectTechniqueActuals,
|
|
{
|
|
data: request,
|
|
},
|
|
);
|
|
await this.developmentEvaluationRepository.remove(development.developmentEvaluations, {
|
|
data: request,
|
|
});
|
|
await this.developmentAddresssRepository.remove(development.developmentAddresss, {
|
|
data: request,
|
|
});
|
|
await this.developmentRiskRepository.remove(development.developmentRisks, {
|
|
data: request,
|
|
});
|
|
//Task #2276 หากลบโครงการให้ตามไปลบที่ทะเบียนประวัติ
|
|
if (development.developmentHistorys != null && development.developmentHistorys.length > 0) {
|
|
// ส่งไปแค่ developmentId เพื่อให้ตามลบที่ทะเบียนประวัติ
|
|
await new CallAPI()
|
|
.PostData(request, "/org/profile/training/delete-all", {
|
|
developmentId: development.id,
|
|
})
|
|
.then((x) => {})
|
|
.catch((x) => {});
|
|
await this.developmentHistoryRepository.remove(development.developmentHistorys, {
|
|
data: request,
|
|
});
|
|
}
|
|
await this.developmentOtherRepository.remove(development.developmentOthers, {
|
|
data: request,
|
|
});
|
|
await this.developmentRepository.remove(development, { data: request });
|
|
return new HttpSuccess();
|
|
}
|
|
|
|
/**
|
|
* API รายการโครงการ/หลักสูตรการฝึกอบรม
|
|
*
|
|
* @summary DEV_004 - รายการโครงการ/หลักสูตรการฝึกอบรม #4
|
|
*
|
|
*/
|
|
@Get()
|
|
async GetDevelopmentLists(
|
|
@Request() request: RequestWithUser,
|
|
@Query("page") page: number = 1,
|
|
@Query("pageSize") pageSize: number = 10,
|
|
@Query("year") year: number,
|
|
@Query("status") status: string,
|
|
@Query("nodeId") nodeId?: string | null,
|
|
@Query("node") node?: number | null,
|
|
@Query("keyword") keyword?: string,
|
|
@Query("sortBy") sortBy?: string,
|
|
@Query("descending") descending?: boolean,
|
|
) {
|
|
let _data = await new permission().PermissionOrgList(request, "SYS_DEV_PROJECT");
|
|
await new CallAPI()
|
|
.PostData(request, "/org/finddna", _data)
|
|
.then((x) => {
|
|
_data = x;
|
|
})
|
|
.catch((x) => {});
|
|
let query = await AppDataSource.getRepository(Development)
|
|
.createQueryBuilder("development")
|
|
.andWhere(year > 0 ? "development.year LIKE :year" : "1=1", {
|
|
year: `${year.toString()}`,
|
|
})
|
|
.andWhere(
|
|
node != undefined && node != null
|
|
? node == 4
|
|
? "development.child4DnaId LIKE :nodeId"
|
|
: node == 3
|
|
? "development.child3DnaId LIKE :nodeId"
|
|
: node == 2
|
|
? "development.child2DnaId LIKE :nodeId"
|
|
: node == 1
|
|
? "development.child1DnaId LIKE :nodeId"
|
|
: "development.rootDnaId LIKE :nodeId"
|
|
: "1=1",
|
|
{
|
|
nodeId: `${nodeId}`,
|
|
},
|
|
)
|
|
.andWhere(status != undefined ? "development.status LIKE :status" : "1=1", {
|
|
status: `%${status}%`,
|
|
})
|
|
.andWhere(
|
|
keyword != undefined
|
|
? new Brackets((qb) => {
|
|
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}%`,
|
|
},
|
|
)
|
|
.andWhere(
|
|
_data.root != undefined && _data.root != null
|
|
? _data.root[0] != null
|
|
? `development.rootDnaId IN (:...root)`
|
|
: `development.rootDnaId is null`
|
|
: "1=1",
|
|
{
|
|
root: _data.root,
|
|
},
|
|
)
|
|
.andWhere(
|
|
_data.child1 != undefined && _data.child1 != null
|
|
? _data.child1[0] != null
|
|
? `development.child1DnaId IN (:...child1)`
|
|
// : `development.child1DnaId is ${_data.privilege == "PARENT" ? "not null" : "null"}`
|
|
: `development.child1DnaId is null`
|
|
: "1=1",
|
|
{
|
|
child1: _data.child1,
|
|
},
|
|
)
|
|
.andWhere(
|
|
_data.child2 != undefined && _data.child2 != null
|
|
? _data.child2[0] != null
|
|
? `development.child2DnaId IN (:...child2)`
|
|
: `development.child2DnaId is null`
|
|
: "1=1",
|
|
{
|
|
child2: _data.child2,
|
|
},
|
|
)
|
|
.andWhere(
|
|
_data.child3 != undefined && _data.child3 != null
|
|
? _data.child3[0] != null
|
|
? `development.child3DnaId IN (:...child3)`
|
|
: `development.child3DnaId is null`
|
|
: "1=1",
|
|
{
|
|
child3: _data.child3,
|
|
},
|
|
)
|
|
.andWhere(
|
|
_data.child4 != undefined && _data.child4 != null
|
|
? _data.child4[0] != null
|
|
? `development.child4DnaId IN (:...child4)`
|
|
: `development.child4DnaId is null`
|
|
: "1=1",
|
|
{
|
|
child4: _data.child4,
|
|
},
|
|
)
|
|
.select([
|
|
"development.id",
|
|
"development.projectName",
|
|
"development.year",
|
|
"development.root",
|
|
"development.child1",
|
|
"development.child2",
|
|
"development.child3",
|
|
"development.child4",
|
|
]);
|
|
|
|
if (sortBy) {
|
|
query = query.orderBy(`development.${sortBy}`, descending ? "DESC" : "ASC");
|
|
} else {
|
|
query = query.orderBy("development.year", "DESC").addOrderBy("development.createdAt", "DESC");
|
|
}
|
|
|
|
const [development, total] = await query
|
|
.skip((page - 1) * pageSize)
|
|
.take(pageSize)
|
|
.getManyAndCount();
|
|
|
|
return new HttpSuccess({ data: development, total });
|
|
}
|
|
|
|
/**
|
|
* API ปิดโครงการ
|
|
*
|
|
* @summary DEV_00 - ปิดโครงการ #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("finish/{id}")
|
|
async FinishDevelopemtById(@Path() id: string, @Request() request: RequestWithUser) {
|
|
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();
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store Development.",
|
|
// });
|
|
await this.developmentRepository.save(getDevelopment, { data: request });
|
|
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}")
|
|
async GetDevelopemtTab1ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
where: { id: id },
|
|
});
|
|
if (!getDevelopment) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let node = null;
|
|
let nodeId = null;
|
|
let nodeDnaId = null;
|
|
if (getDevelopment.child4Id != null) {
|
|
node = 4;
|
|
nodeId = getDevelopment.child4Id;
|
|
nodeDnaId = getDevelopment.child4DnaId;
|
|
} else if (getDevelopment.child3Id != null) {
|
|
node = 3;
|
|
nodeId = getDevelopment.child3Id;
|
|
nodeDnaId = getDevelopment.child3DnaId;
|
|
} else if (getDevelopment.child2Id != null) {
|
|
node = 2;
|
|
nodeId = getDevelopment.child2Id;
|
|
nodeDnaId = getDevelopment.child2DnaId;
|
|
} else if (getDevelopment.child1Id != null) {
|
|
node = 1;
|
|
nodeId = getDevelopment.child1Id;
|
|
nodeDnaId = getDevelopment.child1DnaId;
|
|
} else if (getDevelopment.rootId != null) {
|
|
node = 0;
|
|
nodeId = getDevelopment.rootId;
|
|
nodeDnaId = getDevelopment.rootDnaId;
|
|
}
|
|
|
|
const formattedData = {
|
|
id: getDevelopment.id,
|
|
revisionId: getDevelopment.orgRevisionId,
|
|
year: getDevelopment.year,
|
|
projectName: getDevelopment.projectName,
|
|
reason: getDevelopment.reason,
|
|
objective: getDevelopment.objective,
|
|
node: node,
|
|
nodeId: nodeId,
|
|
nodeDnaId: nodeDnaId,
|
|
root: getDevelopment.rootId,
|
|
child1: getDevelopment.child1Id,
|
|
child2: getDevelopment.child2Id,
|
|
child3: getDevelopment.child3Id,
|
|
child4: getDevelopment.child4Id,
|
|
rootDna: getDevelopment.rootDnaId,
|
|
child1Dna: getDevelopment.child1DnaId,
|
|
child2Dna: getDevelopment.child2DnaId,
|
|
child3Dna: getDevelopment.child3DnaId,
|
|
child4Dna: getDevelopment.child4DnaId,
|
|
};
|
|
return new HttpSuccess(formattedData);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab2
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab2 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab2/{id}")
|
|
async GetDevelopemtTab2ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
where: { id: id },
|
|
//posTypeActual
|
|
relations: [
|
|
"developmentActualPeoples",
|
|
"developmentPlannedPeoples",
|
|
"developmentActualGoals",
|
|
// "developmentActualGoals.posTypeActual",
|
|
// "developmentActualGoals.posLevelActual",
|
|
"developmentActualGoals",
|
|
"developmentPlannedGoals",
|
|
"developmentPlannedGoals.plannedGoalPositions",
|
|
// "developmentPlannedGoals.plannedGoalPositions.posTypePlanned",
|
|
// "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned",
|
|
],
|
|
});
|
|
if (!getDevelopment) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let _getDevelopment: any = {
|
|
id: getDevelopment.id,
|
|
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) => ({
|
|
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,
|
|
})),
|
|
plannedGoals:
|
|
getDevelopment.developmentPlannedGoals == null
|
|
? null
|
|
: getDevelopment.developmentPlannedGoals
|
|
.sort((a, b) =>
|
|
(a.groupTarget == null ? "" : a.groupTarget).localeCompare(
|
|
b.groupTarget == null ? "" : b.groupTarget,
|
|
),
|
|
)
|
|
.map((x) => ({
|
|
id: x.id,
|
|
groupTarget: x.groupTarget,
|
|
groupTargetSub: x.groupTargetSub,
|
|
type: x.type,
|
|
position: x.plannedGoalPositions.map((y) => ({
|
|
id: y.id,
|
|
position: y.position,
|
|
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,
|
|
})),
|
|
};
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab3
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab3 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab3/{id}")
|
|
async GetDevelopemtTab3ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
where: { id: id },
|
|
relations: [
|
|
"developmentProjectTypes",
|
|
"developmentProjectTechniquePlanneds",
|
|
"developmentProjectTechniqueActuals",
|
|
"developmentAddresss",
|
|
],
|
|
});
|
|
if (!getDevelopment) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let _getDevelopment: any = {
|
|
developmentProjectTypes: getDevelopment.developmentProjectTypes.map((x) => x.name).sort(),
|
|
projectModalActual: getDevelopment.projectModalActual,
|
|
projectModalPlanned: getDevelopment.projectModalPlanned,
|
|
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,
|
|
isReasonActual70: getDevelopment.isReasonActual70,
|
|
isReasonActual20: getDevelopment.isReasonActual20,
|
|
isReasonActual10: getDevelopment.isReasonActual10,
|
|
reasonPlanned70: getDevelopment.reasonPlanned70,
|
|
reasonPlanned20: getDevelopment.reasonPlanned20,
|
|
reasonPlanned10: getDevelopment.reasonPlanned10,
|
|
isReasonPlanned70: getDevelopment.isReasonPlanned70,
|
|
isReasonPlanned20: getDevelopment.isReasonPlanned20,
|
|
isReasonPlanned10: getDevelopment.isReasonPlanned10,
|
|
developmentProjectTechniqueActuals: getDevelopment.developmentProjectTechniqueActuals
|
|
.map((x) => x.name)
|
|
.sort(),
|
|
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,
|
|
dateStart: getDevelopment.dateStart,
|
|
dateEnd: getDevelopment.dateEnd,
|
|
totalDate: getDevelopment.totalDate,
|
|
developmentAddresss:
|
|
getDevelopment.developmentAddresss == null
|
|
? null
|
|
: getDevelopment.developmentAddresss.sort(
|
|
(a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
|
|
),
|
|
};
|
|
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,
|
|
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);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab4
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab4 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab4/{id}")
|
|
async GetDevelopemtTab4ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
where: { id: id },
|
|
relations: ["developmentEvaluations"],
|
|
});
|
|
if (!getDevelopment) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let _getDevelopment = {
|
|
developmentEvaluations:
|
|
getDevelopment.developmentEvaluations == null
|
|
? null
|
|
: getDevelopment.developmentEvaluations.sort((a, b) =>
|
|
(a.indicators == null ? "" : a.indicators).localeCompare(
|
|
b.indicators == null ? "" : b.indicators,
|
|
),
|
|
),
|
|
progressTracking: getDevelopment.progressTracking,
|
|
projectEvaluation: getDevelopment.projectEvaluation,
|
|
};
|
|
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab5
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab5 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab5/{id}")
|
|
async GetDevelopemtTab5ById(@Request() request: RequestWithUser, @Path() id: string) {
|
|
let _workflow = await new permission().Workflow(request, id, "SYS_DEV_PROJECT");
|
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
relations: ["developmentOthers"],
|
|
where: { id: id },
|
|
});
|
|
if (!getDevelopment) {
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
|
}
|
|
let _getDevelopment = {
|
|
developmentOthers:
|
|
getDevelopment.developmentOthers == null
|
|
? null
|
|
: getDevelopment.developmentOthers.sort((a, b) =>
|
|
(a.createdAt.toString() == null ? "" : a.createdAt.toString()).localeCompare(
|
|
b.createdAt.toString() == null ? "" : b.createdAt.toString(),
|
|
),
|
|
),
|
|
obstacle: getDevelopment.obstacle,
|
|
suggestion: getDevelopment.suggestion,
|
|
project: getDevelopment.project,
|
|
isPassAllocate: getDevelopment.isPassAllocate,
|
|
isPassNoAllocate: getDevelopment.isPassNoAllocate,
|
|
isNoPass: getDevelopment.isNoPass,
|
|
isBudget: getDevelopment.isBudget,
|
|
isOutBudget: getDevelopment.isOutBudget,
|
|
};
|
|
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab6/{id}")
|
|
async GetDevelopemtTab6ById(@Path() id: string) {
|
|
const getDevelopment = await this.developmentHistoryRepository.find({
|
|
where: { developmentId: id },
|
|
relations: ["posLevel", "posType", "employeePosLevel", "employeePosType"],
|
|
order: {
|
|
no: "ASC",
|
|
isDone: "ASC",
|
|
isDoneIDP: "ASC",
|
|
citizenId: "ASC",
|
|
type: "DESC",
|
|
},
|
|
});
|
|
const _getDevelopment = getDevelopment.map((item) => ({
|
|
no: item.no,
|
|
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,
|
|
org: item.org,
|
|
trainingDays: item.trainingDays,
|
|
commandNumber: item.order,
|
|
commandDate: item.dateOrder,
|
|
dateStart: item.dateStart,
|
|
dateEnd: item.dateEnd,
|
|
isDone: item.isDone,
|
|
isDoneIDP: item.isDoneIDP,
|
|
isProfile: item.isProfile,
|
|
}));
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน)
|
|
*
|
|
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน) #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Get("tab6/done/{id}")
|
|
async GetDevelopemtTab6DoneById(@Path() id: string, @Request() request: RequestWithUser) {
|
|
const getDevelopment = await this.developmentHistoryRepository.find({
|
|
where: { developmentId: id, isDone: false },
|
|
relations: ["development"],
|
|
});
|
|
|
|
const developmentAddresss = await this.developmentAddresssRepository.find({
|
|
where: { developmentId: id },
|
|
});
|
|
|
|
const places = developmentAddresss
|
|
.map(
|
|
(addr) =>
|
|
`- ${addr.address}, ${addr.addressType === "IN_COUNTRY" ? addr.provinceName : addr.country} (${addr.addressType === "IN_COUNTRY" ? "ภายในประเทศ" : "ภายนอกประเทศ"})`,
|
|
)
|
|
.filter(Boolean)
|
|
.join("\n");
|
|
|
|
await Promise.all(
|
|
getDevelopment.map(async (x) => {
|
|
const _data = Object.assign(new DevelopmentHistory(), x);
|
|
if (x.type == "OFFICER") {
|
|
await new CallAPI()
|
|
.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: places == null ? null : places,
|
|
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,
|
|
developmentId: id,
|
|
})
|
|
.then((x) => {
|
|
_data.isDone = true;
|
|
})
|
|
.catch((x) => {
|
|
_data.isDone = false;
|
|
});
|
|
} else if (x.type == "EMPLOYEE") {
|
|
await new CallAPI()
|
|
.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: places == null ? null : places,
|
|
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,
|
|
developmentId: id,
|
|
})
|
|
.then((x) => {
|
|
_data.isDone = true;
|
|
})
|
|
.catch((x) => {
|
|
_data.isDone = 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 รายละเอียดโครงการ/หลักสูตรการฝึกอบรม 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 },
|
|
relations: ["development", "development.developmentProjectTechniqueActuals"],
|
|
});
|
|
|
|
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",
|
|
];
|
|
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));
|
|
|
|
if (x.type == "OFFICER") {
|
|
await new CallAPI()
|
|
.PostData(request, "/org/profile/development", {
|
|
type: "DEVELOP",
|
|
profileId: x.profileId,
|
|
name: x.development.projectName,
|
|
achievement10: null,
|
|
achievement5: null,
|
|
achievement0: null,
|
|
kpiDevelopmentId: x.development.id,
|
|
reasonDevelopment70: x.development.reasonActual70,
|
|
reasonDevelopment20: x.development.reasonActual20,
|
|
reasonDevelopment10: x.development.reasonActual10,
|
|
isDevelopment70: isDevelopment70,
|
|
isDevelopment20: isDevelopment20,
|
|
isDevelopment10: isDevelopment10,
|
|
developmentTarget: null,
|
|
developmentResults: null,
|
|
developmentReport: null,
|
|
developmentProjects: x.development.developmentProjectTechniqueActuals.map(
|
|
(x) => x.name,
|
|
),
|
|
})
|
|
.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,
|
|
name: x.development.projectName,
|
|
achievement10: null,
|
|
achievement5: null,
|
|
achievement0: null,
|
|
kpiDevelopmentId: x.development.id,
|
|
reasonDevelopment70: x.development.reasonActual70,
|
|
reasonDevelopment20: x.development.reasonActual20,
|
|
reasonDevelopment10: x.development.reasonActual10,
|
|
isDevelopment70: isDevelopment70,
|
|
isDevelopment20: isDevelopment20,
|
|
isDevelopment10: isDevelopment10,
|
|
developmentTarget: null,
|
|
developmentResults: null,
|
|
developmentReport: null,
|
|
developmentProjects: x.development.developmentProjectTechniqueActuals.map(
|
|
(x) => x.name,
|
|
),
|
|
})
|
|
.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")
|
|
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,
|
|
@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") {
|
|
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, "ไม่สามารถเข้าถึงข้อมูลนี้ได้");
|
|
}
|
|
|
|
let _getDevelopment: any = {
|
|
id: getDevelopment.id,
|
|
evaluationId: null,
|
|
target: null,
|
|
summary: null,
|
|
point: null,
|
|
name: getDevelopment.projectName,
|
|
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,
|
|
developmentProjects: getDevelopment.developmentProjectTechniqueActuals
|
|
.map((x) => x.name)
|
|
.sort(),
|
|
};
|
|
return new HttpSuccess(_getDevelopment);
|
|
}
|
|
|
|
/**
|
|
* API upload User
|
|
*
|
|
* @summary DEV_0 - upload User #
|
|
*
|
|
* @param {string} id Id โครงการ
|
|
*/
|
|
@Post("tab6/{id}")
|
|
@UseInterceptors(FileInterceptor("file"))
|
|
async UploadUserDevelopemtById(
|
|
@Path() id: string,
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Request() request: RequestWithUser,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
const getDevelopment = await this.developmentRepository.findOne({
|
|
where: { id: id },
|
|
relations: {
|
|
developmentHistorys: true,
|
|
},
|
|
});
|
|
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);
|
|
const before = null;
|
|
await Promise.all(
|
|
getDevelopments.map(async (item: any) => {
|
|
const citizenId:string = item["รหัสประจำตัวประชาชน"] == null || item["รหัสประจำตัวประชาชน"] == ""
|
|
? ""
|
|
: String(item["รหัสประจำตัวประชาชน"]).trim();
|
|
if (citizenId.length !== 13)
|
|
return;
|
|
const oldProfile: any = getDevelopment.developmentHistorys.find(
|
|
(x) => x.citizenId == citizenId,
|
|
);
|
|
if (oldProfile != null) {
|
|
if (oldProfile.isDone == true) return;
|
|
}
|
|
if (item["ประเภท"] == null) return;
|
|
let development = Object.assign(new DevelopmentHistory(), oldProfile);
|
|
if (item["ประเภท"] == "ข้าราชการกรุงเทพมหานครสามัญ" || item["ประเภท"] == "ขรก.กทม. สามัญ") {
|
|
await new CallAPI()
|
|
.GetData(request, `/org/unauthorize/officer/citizen/${citizenId}`)
|
|
.then(async (x: any) => {
|
|
development = Object.assign(development, x);
|
|
development.dateStart = Extension.checkDateTime(item["วันที่เริ่มต้น"]) as Date;
|
|
development.dateEnd = Extension.checkDateTime(item["วันที่สิ้นสุด"])as Date;
|
|
development.order =
|
|
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == null
|
|
? null
|
|
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"].toString();
|
|
development.dateOrder = Extension.checkDateTime(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"])as Date;
|
|
development.trainingDays =
|
|
item["จำนวนวันที่อบรม"] == null ? null : item["จำนวนวันที่อบรม"].toString();
|
|
development.posLevelId = x.posLevelId;
|
|
development.posTypeId = x.posTypeId;
|
|
development.posExecutive = x.posExecutive;
|
|
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 = true;
|
|
development.no = item["ลำดับ"] !== undefined && item["ลำดับ"] !== null && item["ลำดับ"] !== "" && !isNaN(Number(item["ลำดับ"]))
|
|
? Number(item["ลำดับ"])
|
|
: null;
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
})
|
|
.catch(async (x) => {
|
|
let _null: any = null;
|
|
development.prefix = item["คำนำหน้า"] == null ? null : item["คำนำหน้า"].toString();
|
|
development.firstName = item["ชื่อ"] == null ? null : item["ชื่อ"].toString();
|
|
development.lastName = item["นามสกุล"] == null ? null : item["นามสกุล"].toString();
|
|
development.position = item["ตำแหน่ง"] == null ? null : item["ตำแหน่ง"].toString();
|
|
development.org = item["สังกัด"] == null ? null : item["สังกัด"].toString();
|
|
development.dateStart = Extension.checkDateTime(item["วันที่เริ่มต้น"]) as Date;
|
|
development.dateEnd = Extension.checkDateTime(item["วันที่สิ้นสุด"]) as Date;
|
|
development.citizenId = citizenId;
|
|
development.type = "OFFICER" == null ? _null : "OFFICER";
|
|
development.order =
|
|
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == null
|
|
? null
|
|
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"].toString();
|
|
development.dateOrder = Extension.checkDateTime(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]) as Date;
|
|
development.trainingDays =
|
|
item["จำนวนวันที่อบรม"] == null ? null : item["จำนวนวันที่อบรม"].toString();
|
|
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();
|
|
development.isProfile = false;
|
|
development.no = item["ลำดับ"] !== undefined && item["ลำดับ"] !== null && item["ลำดับ"] !== "" && !isNaN(Number(item["ลำดับ"]))
|
|
? Number(item["ลำดับ"])
|
|
: null;
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
});
|
|
}
|
|
else if (item["ประเภท"] == "ลูกจ้างประจำ") {
|
|
await new CallAPI()
|
|
.GetData(request, `/org/unauthorize/employee/citizen/${citizenId}`)
|
|
.then(async (x: any) => {
|
|
development = Object.assign(development, x);
|
|
development.dateStart = Extension.checkDateTime(item["วันที่เริ่มต้น"]) as Date;
|
|
development.dateEnd = Extension.checkDateTime(item["วันที่สิ้นสุด"]) as Date;
|
|
development.order =
|
|
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == null
|
|
? null
|
|
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"].toString();
|
|
development.dateOrder = Extension.checkDateTime(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]) as Date;
|
|
development.trainingDays =
|
|
item["จำนวนวันที่อบรม"] == null ? null : item["จำนวนวันที่อบรม"].toString();
|
|
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();
|
|
development.isProfile = true;
|
|
development.no = item["ลำดับ"] !== undefined && item["ลำดับ"] !== null && item["ลำดับ"] !== "" && !isNaN(Number(item["ลำดับ"]))
|
|
? Number(item["ลำดับ"])
|
|
: null;
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
})
|
|
.catch(async (x) => {
|
|
let _null: any = null;
|
|
development.prefix = item["คำนำหน้า"] == null ? null : item["คำนำหน้า"].toString();
|
|
development.firstName = item["ชื่อ"] == null ? null : item["ชื่อ"].toString();
|
|
development.lastName = item["นามสกุล"] == null ? null : item["นามสกุล"].toString();
|
|
development.position = item["ตำแหน่ง"] == null ? null : item["ตำแหน่ง"].toString();
|
|
development.org = item["สังกัด"] == null ? null : item["สังกัด"].toString();
|
|
development.dateStart = Extension.checkDateTime(item["วันที่เริ่มต้น"]) as Date;
|
|
development.dateEnd = Extension.checkDateTime(item["วันที่สิ้นสุด"]) as Date;
|
|
development.citizenId = citizenId;
|
|
development.type = "EMPLOYEE" == null ? _null : "EMPLOYEE";
|
|
development.order =
|
|
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == null
|
|
? null
|
|
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"].toString();
|
|
development.dateOrder = Extension.checkDateTime(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]) as Date;
|
|
development.trainingDays =
|
|
item["จำนวนวันที่อบรม"] == null ? null : item["จำนวนวันที่อบรม"].toString();
|
|
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();
|
|
development.isProfile = false;
|
|
development.no = item["ลำดับ"] !== undefined && item["ลำดับ"] !== null && item["ลำดับ"] !== "" && !isNaN(Number(item["ลำดับ"]))
|
|
? Number(item["ลำดับ"])
|
|
: null;
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
});
|
|
}
|
|
else {
|
|
let development = new DevelopmentHistory();
|
|
let _null: any = null;
|
|
development.prefix = item["คำนำหน้า"] == null ? null : item["คำนำหน้า"].toString();
|
|
development.firstName = item["ชื่อ"] == null ? null : item["ชื่อ"].toString();
|
|
development.lastName = item["นามสกุล"] == null ? null : item["นามสกุล"].toString();
|
|
development.position = item["ตำแหน่ง"] == null ? null : item["ตำแหน่ง"].toString();
|
|
development.org = item["สังกัด"] == null ? null : item["สังกัด"].toString();
|
|
development.dateStart = Extension.checkDateTime(item["วันที่เริ่มต้น"]) as Date;
|
|
development.dateEnd = Extension.checkDateTime(item["วันที่สิ้นสุด"]) as Date;
|
|
development.citizenId = citizenId;
|
|
development.type = "OTHER";
|
|
development.order =
|
|
item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"] == null
|
|
? null
|
|
: item["เลขที่คำสั่ง/เลขที่หนังสืออนุมัติ"].toString();
|
|
development.dateOrder = Extension.checkDateTime(item["คำสั่งลงวันที่/หนังสืออนุมัติลงวันที่"]) as Date;
|
|
development.trainingDays =
|
|
item["จำนวนวันที่อบรม"] == null ? null : item["จำนวนวันที่อบรม"] .toString();
|
|
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;
|
|
development.no = item["ลำดับ"] !== undefined && item["ลำดับ"] !== null && item["ลำดับ"] !== "" && !isNaN(Number(item["ลำดับ"]))
|
|
? Number(item["ลำดับ"])
|
|
: null;
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
}
|
|
}),
|
|
);
|
|
return new HttpSuccess(getDevelopments);
|
|
}
|
|
/**
|
|
* 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,
|
|
) {
|
|
await new permission().PermissionCreate(request, "SYS_DEV_PROJECT");
|
|
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) {
|
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ข้อมูลนี้ได้ถูกบันทึกแล้ว");
|
|
}
|
|
if (oldProfile != null) {
|
|
if (oldProfile.isDone == true)
|
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ข้อมูลนี้ได้ถูกบันทึกแล้ว");
|
|
oldProfile.dateStart = requestBody.dateStart == null ? _null : requestBody.dateStart;
|
|
oldProfile.dateEnd = requestBody.dateEnd == null ? _null : requestBody.dateEnd;
|
|
oldProfile.order = requestBody.commandNumber == null ? _null : requestBody.commandNumber;
|
|
oldProfile.dateOrder = requestBody.commandDate == null ? _null : new Date(requestBody.commandDate);
|
|
oldProfile.trainingDays = requestBody.trainingDays == null ? _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();
|
|
if(requestBody.no !== undefined && requestBody.no !== null && requestBody.no !== "" && !isNaN(Number(requestBody.no))) {
|
|
oldProfile.no = Number(requestBody.no);
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentHistory.",
|
|
// });
|
|
await this.developmentHistoryRepository.save(oldProfile, { data: request });
|
|
setLogDataDiff(request, { before, after: oldProfile });
|
|
status = oldProfile.isProfile;
|
|
}
|
|
|
|
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 == null ? _null : requestBody.dateStart;
|
|
development.dateEnd = requestBody.dateEnd == null ? _null : requestBody.dateEnd;
|
|
development.order =
|
|
requestBody.commandNumber == null ? _null : requestBody.commandNumber;
|
|
development.dateOrder =
|
|
requestBody.commandDate == null ? _null : requestBody.commandDate;
|
|
development.trainingDays =
|
|
requestBody.trainingDays == null ? _null : requestBody.trainingDays;
|
|
development.posLevelId = x.posLevelId == null ? _null : x.posLevelId;
|
|
development.posTypeId = x.posTypeId == null ? _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();
|
|
if(requestBody.no !== undefined && requestBody.no !== null && requestBody.no !== "" && !isNaN(Number(requestBody.no))) {
|
|
development.no = Number(requestBody.no);
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentHistory.",
|
|
// });
|
|
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 == null ? _null : requestBody.prefix;
|
|
development.firstName =
|
|
requestBody.firstName == null ? _null : requestBody.firstName;
|
|
development.lastName = requestBody.lastName == null ? _null : requestBody.lastName;
|
|
development.position = requestBody.position == null ? _null : requestBody.position;
|
|
development.org = requestBody.org == null ? _null : requestBody.org;
|
|
development.dateStart =
|
|
requestBody.dateStart == null ? _null : requestBody.dateStart;
|
|
development.dateEnd = requestBody.dateEnd == null ? _null : requestBody.dateEnd;
|
|
development.citizenId =
|
|
requestBody.citizenId == null ? _null : requestBody.citizenId;
|
|
development.type = requestBody.type == null ? _null : requestBody.type;
|
|
development.order =
|
|
requestBody.commandNumber == null ? _null : requestBody.commandNumber;
|
|
development.dateOrder =
|
|
requestBody.commandDate == null ? _null : requestBody.commandDate;
|
|
development.trainingDays =
|
|
requestBody.trainingDays == null ? _null : requestBody.trainingDays;
|
|
development.posLevelId = x.posLevelId == null ? _null : x.posLevelId;
|
|
development.posTypeId = x.posTypeId == null ? _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();
|
|
development.isProfile = false;
|
|
if(requestBody.no !== undefined && requestBody.no !== null && requestBody.no !== "" && !isNaN(Number(requestBody.no))) {
|
|
development.no = Number(requestBody.no);
|
|
}
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentHistory.",
|
|
// });
|
|
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 == null ? _null : requestBody.dateStart;
|
|
development.dateEnd = requestBody.dateEnd == null ? _null : requestBody.dateEnd;
|
|
development.order =
|
|
requestBody.commandNumber == null ? _null : requestBody.commandNumber;
|
|
development.dateOrder =
|
|
requestBody.commandDate == null ? _null : requestBody.commandDate;
|
|
development.trainingDays =
|
|
requestBody.trainingDays == null ? _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();
|
|
development.isProfile = true;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentHistory.",
|
|
// });
|
|
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 == null ? _null : requestBody.prefix;
|
|
development.firstName =
|
|
requestBody.firstName == null ? _null : requestBody.firstName;
|
|
development.lastName = requestBody.lastName == null ? _null : requestBody.lastName;
|
|
development.position = requestBody.position == null ? _null : requestBody.position;
|
|
development.org = requestBody.org == null ? _null : requestBody.org;
|
|
development.dateStart =
|
|
requestBody.dateStart == null ? _null : requestBody.dateStart;
|
|
development.dateEnd = requestBody.dateEnd == null ? _null : requestBody.dateEnd;
|
|
development.citizenId =
|
|
requestBody.citizenId == null ? _null : requestBody.citizenId;
|
|
development.type = requestBody.type == null ? _null : requestBody.type;
|
|
development.order =
|
|
requestBody.commandNumber == null ? _null : requestBody.commandNumber;
|
|
development.dateOrder =
|
|
requestBody.commandDate == null ? _null : requestBody.commandDate;
|
|
development.trainingDays =
|
|
requestBody.trainingDays == null ? _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();
|
|
development.isProfile = false;
|
|
// addLogSequence(request, {
|
|
// action: "database",
|
|
// status: "success",
|
|
// description: "Store DevelopmentHistory.",
|
|
// });
|
|
await this.developmentHistoryRepository.save(development, { data: request });
|
|
setLogDataDiff(request, { before, after: development });
|
|
status = development.isProfile;
|
|
});
|
|
}
|
|
return new HttpSuccess(status);
|
|
}
|
|
}
|