hrms-api-eva/src/controllers/EvaluationController.ts
2025-04-23 12:14:39 +07:00

3137 lines
118 KiB
TypeScript

import { AppDataSource } from "../database/data-source";
import {
Body,
Example,
Get,
Path,
Post,
Put,
Request,
Response,
Route,
Security,
SuccessResponse,
Tags,
Delete,
} from "tsoa";
import HttpStatusCode from "../interfaces/http-status";
import { Evaluation, CreateEvaluation, CreateEvaluationExpertise } from "../entities/Evaluation";
import HttpSuccess from "../interfaces/http-success";
import { EvaluationLogs } from "../entities/EvaluationLogs";
import HttpError from "../interfaces/http-error";
import { Education } from "../entities/Education";
import { Certificate } from "../entities/Certificate";
import { Salary } from "../entities/Salary";
import { Training } from "../entities/Training";
import { Assessment } from "../entities/Assessment";
import { Director } from "../entities/Director";
import { Meeting } from "../entities/Meeting";
import { ConvertThaiToType, ConvertToThaiStep, ConvertToThaiType } from "../services/storage";
import { Brackets, In } from "typeorm";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import Extension from "../interfaces/extension";
import { Portfolio } from "../entities/Portfolio";
import { Performance } from "../entities/Performance";
import { AnnounceTemplate } from "../entities/AnnounceTemplate";
@Route("api/v1/evaluation")
@Tags("evaluation")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถทำรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class EvaluationController {
private evaluationRepository = AppDataSource.getRepository(Evaluation);
private evaluationLogsRepository = AppDataSource.getRepository(EvaluationLogs);
private educationRepository = AppDataSource.getRepository(Education);
private certificateRepository = AppDataSource.getRepository(Certificate);
private salaryRepository = AppDataSource.getRepository(Salary);
private trainingRepository = AppDataSource.getRepository(Training);
private assessmentRepository = AppDataSource.getRepository(Assessment);
private portfolioRepository = AppDataSource.getRepository(Portfolio);
private performanceRepository = AppDataSource.getRepository(Performance);
private directorRepository = AppDataSource.getRepository(Director);
private meetingRepository = AppDataSource.getRepository(Meeting);
private announceTemplateRepository = AppDataSource.getRepository(AnnounceTemplate);
/**
* API ล้างข้อมูล
*
* @summary ล้างข้อมูล
*
*/
@Get("clear-db")
async ClearDb() {
return new HttpSuccess();
}
/**
* API รายการผลงานที่เคยเสนอขอประเมิน
*
* @summary รายการผลงานที่เคยเสนอขอประเมิน
*
*/
@Get("performance/user")
async listPerformance(@Request() request: RequestWithUser) {
const list = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.where("evaluation.userId = :userId", { userId: request.user.sub })
.andWhere("evaluation.step = :step", { step: "DONE" })
.andWhere("evaluation.evaluationResult IN (:...evaluationResult)", {
evaluationResult: ["PASS", "NOTPASS"],
})
.select([
"evaluation.id",
"evaluation.type",
"evaluation.subject",
"evaluation.evaluationResult",
"evaluation.lastUpdatedAt",
])
.orderBy("evaluation.lastUpdatedAt", "ASC")
.getMany();
const performance = list.map((item) => ({
id: item.id,
year: item.lastUpdatedAt?Extension.ToThaiYear(item.lastUpdatedAt.getFullYear()):null,
type: item.type == "EXPERT" ? "ชำนาญการ" : item.type == "EXPERTISE" ? "เชียวชาญ" : item.type == "SPECIAL_EXPERT" ? "ชำนาญการพิเศษ": null,
subject: item.subject?item.subject[0]:null,
evaluationResult: item.evaluationResult == "PASS" ? "ผ่าน" : item.evaluationResult == "NOTPASS" ? "ไม่ผ่าน" : null,
}));
return new HttpSuccess(performance);
}
/**
* ดึงข้อมูลรายการร้องขอการประเมิน
*
* @summary รายการร้องขอการประเมิน
*
*/
@Post()
@Example([
{
keyword: "นัทธิชา ปุ่นอุดม",
page: "1",
pageSize: "25",
status: ["PREPARE_DOC_V2", "DONE"],
},
])
async lists(
@Request() request: RequestWithUser,
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
status?: string[];
},
) {
try {
// await new permission().PermissionList(request, "SYS_EVA_REQ");
let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ");
const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.andWhere(
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `evaluation.rootDnaId IN (:...root)`
: `evaluation.rootDnaId is null`
: "1=1",
{
root: _data.root,
},
)
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `evaluation.child1DnaId IN (:...child1)`
: `evaluation.child1DnaId is null`
: "1=1",
{
child1: _data.child1,
},
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `evaluation.child2DnaId IN (:...child2)`
: `evaluation.child2DnaId is null`
: "1=1",
{
child2: _data.child2,
},
)
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `evaluation.child3DnaId IN (:...child3)`
: `evaluation.child3DnaId is null`
: "1=1",
{
child3: _data.child3,
},
)
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `evaluation.child4DnaId IN (:...child4)`
: `evaluation.child4DnaId is null`
: "1=1",
{
child4: _data.child4,
},
)
.andWhere(
new Brackets((qb) => {
qb.andWhere(
body.status == undefined ||
body.status == null ||
body.status.every((s) => s === "ALL")
? "1=1"
: `evaluation.step In (:status)`,
{
status: body.status,
},
).andWhere(
new Brackets((qb) => {
qb.orWhere("evaluation.fullName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("evaluation.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("evaluation.position LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("evaluation.posNo LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("evaluation.oc LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("evaluation.type IN (:...type)", {
type: body.keyword == null ? [""] : ConvertThaiToType(body.keyword),
});
}),
);
}),
)
.orderBy("evaluation.lastUpdatedAt", "DESC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลรายการร้องขอการประเมิน สำหรับ USER
*
* @summary รายการร้องขอการประเมิน (USER)
*
*/
@Put("user")
@Example([
{
keyword: "ชำนาญการพิเศษ",
page: "1",
pageSize: "25",
status: ["PREPARE_DOC_V2", "DONE"],
},
])
async user_lists(
@Request() request: RequestWithUser,
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
status?: string[];
},
) {
try {
const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.andWhere(
new Brackets((qb) => {
qb.andWhere(
body.status == undefined ||
body.status == null ||
body.status.every((s) => s === "ALL")
? "1=1"
: `evaluation.step In (:status)`,
{
status: body.status,
},
).andWhere("evaluation.createdUserId = :createdUserId", {
createdUserId: request.user.sub,
});
}),
)
.orderBy("evaluation.lastUpdatedAt", "DESC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
const _evaluation = evaluation.map((item) => ({
id: item.id,
citizenId: item.citizenId,
fullName: item.fullName,
position: item.position,
oc: item.oc,
posNo: item.posNo,
type: item.type,
type_th: ConvertToThaiType(item.type),
step: item.step,
step_th: ConvertToThaiStep(item.step),
createdAt: item.createdAt,
updatedAt: item.lastUpdatedAt,
}));
return new HttpSuccess({ data: _evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลสถานะสิทธิร้องขอการประเมิน
*
* @summary EV1_001 - เช็คการยื่นขอประเมิน (USER)
*
*/
@Get("check-status")
@Example([
{
isExpert: "true",
expertId: "00000000-0000-0000-0000-000000000000",
isSpecialExpert: "false",
specialExpertId: "00000000-0000-0000-0000-000000000000",
},
])
async checkStatus(@Request() request: { user: { sub: string; name: string } }) {
try {
const userId = request.user.sub; //UserId
const fullName = request.user.name; //FullName
const status = await this.evaluationRepository.find({
where: {
userId: userId,
},
select: {
type: true,
id: true,
},
});
const isExpert = status.some((item) => item.type === "EXPERT");
const isSpecialExpert = status.some((item) => item.type === "SPECIAL_EXPERT");
const isExpertise = status.some((item) => item.type === "EXPERTISE");
const expertId = status.find((item) => item.type === "EXPERT")?.id || null;
const specialExpertId = status.find((item) => item.type === "SPECIAL_EXPERT")?.id || null;
const expertiseId = status.find((item) => item.type === "EXPERTISE")?.id || null;
const responseData = {
isExpert,
isSpecialExpert,
isExpertise,
expertId,
specialExpertId,
expertiseId,
};
return new HttpSuccess(responseData);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API get template ประกาศคัดเลือก
*
* @summary get template ประกาศคัดเลือก (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("get-announce-template/{id}")
async getAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser) {
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } , select: ["id","detailAnnounceStep5Body","detailAnnounceStep5Footer"]});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลรายละเอียด step การขอประเมิน
*
* @summary EV1_002 - รายละเอียด step การขอประเมิน (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("check/{id}")
@Example([
{
step: "string",
},
])
async check(@Request() request: RequestWithUser, @Path() id: string) {
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: ["step"],
});
if (!evaluation) {
return "ไม่พบข้อมูล";
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* เลือกรายละเอียดตรวจสอบคุณสมบัติ
*
* @summary EV1_004 - บันทึกตรวจสอบคุณสมบัติ (USER)
*
*/
@Post("check-spec")
@Example([
{
isEducationalQft: "false",
isGovermantServiceHtr: "false",
isOperatingExp: "false",
isMinPeriodOfTenure: "false",
isHaveSpecificQft: "false",
isHaveProLicense: "false",
isHaveMinPeriodOrHoldPos: "false",
type: "EXPERT",
prefix: null,
fullname: null,
position: null,
posNo: null,
oc: null,
salary: null,
root: null,
orgRootId: null,
positionLevel: null,
birthDate: null,
govAge: null,
experience: null,
educations: [
{
educationLevel: "ต่ำกว่าปริญญาตรี",
institute: "มจธ",
isDate: true,
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
finishDate: "2023-12-14T00:00:00",
isEducation: false,
degree: "-",
field: "-",
fundName: "-",
gpa: "-",
country: "-",
other: "-",
duration: "-",
durationYear: 4,
},
],
certificates: [
{
certificateType: "-",
issuer: "-",
certificateNo: "-",
issueDate: "2023-12-14T00:00:00",
expireDate: "2023-12-14T00:00:00",
},
],
salaries: [
{
date: "2023-10-11T16:15:00.185384",
Amount: 30220,
positionSalaryAmount: null,
mouthSalaryAmount: null,
position: "นักทรัพยากรบุคคล",
posNo: "สกจ.5",
salaryClass: null,
salaryRef: null,
refCommandNo: null,
refCommandDate: null,
salaryStatus: null,
},
],
trainings: [
{
name: "-",
topic: "-",
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
yearly: 2023,
place: "-",
duration: "-",
department: "-",
numberOrder: "-",
dateOrder: "2023-12-14T02:54:30.448",
},
],
assessments: [
{
date: "2023-12-14T00:00:00",
point1Total: 60,
point1: 46,
point2Total: 40,
point2: 34,
pointSumTotal: 100,
pointSum: 80,
},
],
},
])
async save(@Body() requestBody: CreateEvaluation, @Request() request: RequestWithUser) {
// await new permission().PermissionCreate(request, "SYS_EVA_REQ");
try {
const _null: any = null;
const evaluation = Object.assign(new Evaluation(), requestBody);
if (!evaluation) {
return `not found data`;
}
const announceTemplate5 = await this.announceTemplateRepository.findOne({
where:{
code : "ST05-1"
},
select: ["detailBody","detailFooter"]
})
const before = null;
await new CallAPI()
.GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`)
.then(async (x) => {
evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId;
})
.catch();
evaluation.step = "PREPARE_DOC_V1";
evaluation.type = requestBody.type == "EXPERT" ? "EXPERT" : "SPECIAL_EXPERT";
evaluation.fullName = requestBody.fullName;
evaluation.createdFullName = request.user.name;
evaluation.createdUserId = request.user.sub;
evaluation.createdAt = new Date();
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
evaluation.userId = request.user.sub;
evaluation.detailAnnounceStep5Body = announceTemplate5?.detailBody??_null;
evaluation.detailAnnounceStep5Footer = announceTemplate5?.detailFooter??_null;
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
//Education
if (requestBody.educations != null)
requestBody.educations.forEach(async (edu) => {
const education = new Education();
education.createdUserId = request.user.sub;
education.createdFullName = request.user.name;
education.createdAt = new Date();
education.lastUpdateUserId = request.user.sub;
education.lastUpdateFullName = request.user.name;
education.lastUpdatedAt = new Date();
education.educationLevel = edu.educationLevel ?? _null;
education.institute = edu.institute ?? _null;
education.isDate = edu.isDate ?? _null;
education.startDate = edu.startDate ?? _null;
education.endDate = edu.endDate ?? _null;
education.finishDate = edu.finishDate ?? _null;
education.isEducation = edu.isEducation ?? _null;
education.degree = edu.degree ?? _null;
education.field = edu.field ?? _null;
education.fundName = edu.fundName ?? _null;
education.gpa = edu.gpa ?? _null;
education.country = edu.country ?? _null;
education.other = edu.other ?? _null;
education.duration = edu.duration ?? _null;
education.durationYear = edu.durationYear ?? _null;
education.evaluation = evaluation;
await this.educationRepository.save(education, { data: request });
setLogDataDiff(request, { before, after: evaluation });
});
//Certificate
if (requestBody.certificates != null)
requestBody.certificates.forEach(async (certi) => {
const certificate = new Certificate();
certificate.createdUserId = request.user.sub;
certificate.createdFullName = request.user.name;
certificate.createdAt = new Date();
certificate.lastUpdateUserId = request.user.sub;
certificate.lastUpdateFullName = request.user.name;
certificate.lastUpdatedAt = new Date();
certificate.certificateType = certi.certificateType ?? _null;
certificate.issuer = certi.issuer ?? _null;
certificate.certificateNo = certi.certificateNo ?? _null;
certificate.issueDate = certi.issueDate ?? _null;
certificate.expireDate = certi.expireDate ?? _null;
certificate.evaluation = evaluation;
await this.certificateRepository.save(certificate, { data: request });
setLogDataDiff(request, { before, after: certificate });
});
//Salary
// if (requestBody.salaries != null)
// requestBody.salaries.forEach(async (salary) => {
// const salaries = new Salary();
// salaries.createdUserId = request.user.sub;
// salaries.createdFullName = request.user.name;
// salaries.createdAt = new Date();
// salaries.lastUpdateUserId = request.user.sub;
// salaries.lastUpdateFullName = request.user.name;
// salaries.lastUpdatedAt = new Date();
// salaries.date = salary.date ?? _null;
// salaries.amount = salary.amount ?? _null;
// salaries.positionSalaryAmount = salary.positionSalaryAmount ?? _null;
// salaries.mouthSalaryAmount = salary.mouthSalaryAmount ?? _null;
// salaries.position = salary.position ?? _null;
// salaries.posNo = salary.posNo ?? _null;
// salaries.salaryClass = salary.salaryClass ?? _null;
// salaries.salaryRef = salary.salaryRef ?? _null;
// salaries.refCommandNo = salary.refCommandNo ?? _null;
// salaries.refCommandDate = salary.refCommandDate ?? _null;
// salaries.salaryStatus = salary.salaryStatus ?? _null;
// salaries.evaluation = evaluation;
// await this.salaryRepository.save(salaries, { data: request });
// setLogDataDiff(request, { before, after: salaries });
// });
if (requestBody.salaries != null) {
requestBody.salaries.forEach(async (salary) => {
const salaries = new Salary();
salaries.profileId = salary.profileId ?? _null;
salaries.commandCode = salary.commandCode ?? _null;
salaries.commandNo = salary.commandNo ?? _null;
salaries.commandYear = salary.commandYear ?? _null;
salaries.commandDateAffect = salary.commandDateAffect ?? _null;
salaries.commandDateSign = salary.commandDateSign ?? _null;
salaries.posNoAbb = salary.posNoAbb ?? _null;
salaries.posNo = salary.posNo ?? _null;
salaries.positionName = salary.positionName ?? _null;
salaries.positionType = salary.positionType ?? _null;
salaries.positionLevel = salary.positionLevel ?? _null;
salaries.positionLine = salary.positionLine ?? _null;
salaries.positionPathSide = salary.positionPathSide ?? _null;
salaries.positionExecutive = salary.positionExecutive ?? _null;
salaries.amount = salary.amount ?? _null;
salaries.amountSpecial = salary.amountSpecial ?? _null;
salaries.positionSalaryAmount = salary.positionSalaryAmount ?? _null;
salaries.mouthSalaryAmount = salary.mouthSalaryAmount ?? _null;
salaries.orgRoot = salary.orgRoot ?? _null;
salaries.orgChild1 = salary.orgChild1 ?? _null;
salaries.orgChild2 = salary.orgChild2 ?? _null;
salaries.orgChild3 = salary.orgChild3 ?? _null;
salaries.orgChild4 = salary.orgChild4 ?? _null;
salaries.remark = salary.remark ?? _null;
salaries.commandId = salary.commandId ?? _null;
salaries.isGovernment = salary.isGovernment ?? _null;
salaries.positionCee = salary.positionCee ?? _null;
salaries.commandName = salary.commandName ?? _null;
salaries.posNumCodeSit = salary.posNumCodeSit ?? _null;
salaries.posNumCodeSitAbb = salary.posNumCodeSitAbb ?? _null;
salaries.isEntry = salary.isEntry ?? false;
salaries.evaluation = evaluation;
salaries.createdUserId = request.user.sub;
salaries.createdFullName = request.user.name;
salaries.createdAt = new Date();
salaries.lastUpdateUserId = request.user.sub;
salaries.lastUpdateFullName = request.user.name;
salaries.lastUpdatedAt = new Date();
await this.salaryRepository.save(salaries, { data: request });
setLogDataDiff(request, { before, after: salaries });
});
}
//Training
if (requestBody.trainings != null)
requestBody.trainings.forEach(async (train) => {
const training = new Training();
training.createdUserId = request.user.sub;
training.createdFullName = request.user.name;
training.createdAt = new Date();
training.lastUpdateUserId = request.user.sub;
training.lastUpdateFullName = request.user.name;
training.lastUpdatedAt = new Date();
training.name = train.name ?? _null;
training.topic = train.topic ?? _null;
training.startDate = train.startDate ?? _null;
training.endDate = train.endDate ?? _null;
training.yearly = train.yearly ?? _null;
training.place = train.place ?? _null;
training.duration = train.duration ?? _null;
training.department = train.department ?? _null;
training.numberOrder = train.numberOrder ?? _null;
training.dateOrder = train.dateOrder ?? _null;
training.evaluation = evaluation;
await this.trainingRepository.save(training, { data: request });
setLogDataDiff(request, { before, after: training });
});
//Assessment
if (requestBody.assessments != null)
requestBody.assessments.forEach(async (asmt) => {
const assessment = new Assessment();
assessment.createdUserId = request.user.sub;
assessment.createdFullName = request.user.name;
assessment.createdAt = new Date();
assessment.lastUpdateUserId = request.user.sub;
assessment.lastUpdateFullName = request.user.name;
assessment.lastUpdatedAt = new Date();
assessment.date = asmt.date ?? _null;
assessment.point1Total = asmt.point1Total ?? _null;
assessment.point1 = asmt.point1 ?? _null;
assessment.point2Total = asmt.point2Total ?? _null;
assessment.point2 = asmt.point2 ?? _null;
assessment.pointSumTotal = asmt.pointSumTotal ?? _null;
assessment.pointSum = asmt.pointSum ?? _null;
assessment.evaluation = evaluation;
await this.assessmentRepository.save(assessment, { data: request });
setLogDataDiff(request, { before, after: assessment });
});
//Portfolio
if (requestBody.portfolios != null)
requestBody.portfolios.forEach(async (pfo) => {
const portfolio = new Portfolio();
portfolio.createdUserId = request.user.sub;
portfolio.createdFullName = request.user.name;
portfolio.createdAt = new Date();
portfolio.lastUpdateUserId = request.user.sub;
portfolio.lastUpdateFullName = request.user.name;
portfolio.lastUpdatedAt = new Date();
portfolio.name = pfo.name ?? _null;
portfolio.detail = pfo.detail ?? _null;
portfolio.evaluation = evaluation;
await this.portfolioRepository.save(portfolio, { data: request });
setLogDataDiff(request, { before, after: portfolio });
});
//Performance
if (requestBody.performances != null)
requestBody.performances.forEach(async (pfm) => {
const performance = new Performance();
performance.createdUserId = request.user.sub;
performance.createdFullName = request.user.name;
performance.createdAt = new Date();
performance.lastUpdateUserId = request.user.sub;
performance.lastUpdateFullName = request.user.name;
performance.lastUpdatedAt = new Date();
performance.year = pfm.year ?? _null;
performance.type = pfm.type ?? _null;
performance.subject = pfm.subject ?? _null;
performance.evaluationResult = pfm.evaluationResult ?? _null;
performance.evaluation = evaluation;
await this.performanceRepository.save(performance, { data: request });
setLogDataDiff(request, { before, after: performance });
});
//EvaluationLogs
const evaluationLogs = new EvaluationLogs();
evaluationLogs.step = (await ConvertToThaiStep("PREPARE_DOC_V1")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs);
setLogDataDiff(request, { before, after: evaluationLogs });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${requestBody.fullName} ทำการยื่นขอประเมิน`,
body: `${requestBody.fullName} ทำการยื่นขอประเมิน`,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess({
id: evaluation.id,
});
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
*
*
*/
@Post("expertise")
async saveExpertise(
@Body() requestBody: CreateEvaluationExpertise,
@Request() request: RequestWithUser,
) {
// await new permission().PermissionCreate(request, "SYS_EVA_REQ");
try {
const evaluation = Object.assign(new Evaluation(), requestBody);
const before = null;
let org: any;
await new CallAPI()
.GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`)
.then(async (x) => {
org = x.org;
evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId;
})
.catch();
//Evaluation
evaluation.oc = org;
evaluation.step = "DONE";
evaluation.type = "EXPERTISE";
evaluation.userId = request.user.sub;
evaluation.createdFullName = request.user.name;
evaluation.createdUserId = request.user.sub;
evaluation.createdAt = new Date();
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
evaluation.userId = request.user.sub;
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
//EvaluationLogs
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("DONE")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${request.user.name} ทำการยื่นขอประเมิน`,
body: `${request.user.name} ทำการยื่นขอประเมิน`,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess({
id: evaluation.id,
});
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API อัพเดทสถานะผลการประเมิน
*
* @summary อัพเดทสถานะผลการประเมิน
*
* @param {string} id id การประเมิน
*/
@Put("updateEvaluationResult/{id}")
async updateEvaluationResult(
@Request() request: RequestWithUser,
@Path() id: string,
@Body() body: { result: string },
) {
try {
const result = body.result.toUpperCase();
if (result !== "PASS" && result !== "NOTPASS" && result !== "PENDING") {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผลลัพธ์ดังกล่าว");
}
const evaluation = await this.evaluationRepository.findOne({
where: { id },
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
evaluation.evaluationResult = result;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
*
*
*/
@Get("expertise/{id}")
async getExpertise(@Path() id: string) {
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"id",
"author",
"subject",
"commanderFullname",
"commanderPosition",
"commanderAboveFullname",
"commanderAbovePosition",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลรายละเอียดตรวจสอบคุณสมบัติ
*
* @summary EV1_003 - รายละเอียดตรวจสอบคุณสมบัติ (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("check-spec/{id}")
@Example([
{
isEducationalQft: "false",
isGovermantServiceHtr: "false",
isOperatingExp: "false",
isMinPeriodOfTenure: "false",
isHaveSpecificQft: "false",
isHaveProLicense: "false",
isHaveMinPeriodOrHoldPos: "false",
type: "EXPERT",
prefix: null,
fullname: null,
position: null,
posNo: null,
oc: null,
salary: null,
positionLevel: null,
birthDate: null,
govAge: null,
experience: null,
educations: [
{
educationLevel: "ต่ำกว่าปริญญาตรี",
institute: "มจธ",
isDate: true,
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
finishDate: "2023-12-14T00:00:00",
isEducation: false,
degree: "-",
field: "-",
fundName: "-",
gpa: "-",
country: "-",
other: "-",
duration: "-",
durationYear: 4,
},
],
certificates: [
{
certificateType: "-",
issuer: "-",
certificateNo: "-",
issueDate: "2023-12-14T00:00:00",
expireDate: "2023-12-14T00:00:00",
},
],
salaries: [
{
date: "2023-10-11T16:15:00.185384",
amount: 30220,
positionSalaryAmount: null,
mouthSalaryAmount: null,
position: "นักทรัพยากรบุคคล",
posNo: "สกจ.5",
salaryClass: null,
salaryRef: null,
refCommandNo: null,
refCommandDate: null,
salaryStatus: null,
},
],
trainings: [
{
name: "-",
topic: "-",
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
yearly: 2023,
place: "-",
duration: "-",
department: "-",
numberOrder: "-",
dateOrder: "2023-12-14T02:54:30.448",
},
],
assessments: [
{
date: "2023-12-14T00:00:00",
point1Total: 60,
point1: 46,
point2Total: 40,
point2: 34,
pointSumTotal: 100,
pointSum: 80,
},
],
},
])
async checkSpecGet(@Request() request: RequestWithUser, @Path() id: string) {
try {
// let thaiYear: number = new Date().getFullYear() + 543;
// let years = {
// lastTwoYear: Extension.ToThaiNumber((thaiYear - 2).toString()),
// lastOneYear: Extension.ToThaiNumber((thaiYear - 1).toString()),
// currentYear: Extension.ToThaiNumber(thaiYear.toString()),
// };
const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.leftJoin("evaluation.education", "education")
.leftJoin("evaluation.certificate", "certificate")
.leftJoin("evaluation.salaries", "salaries")
.leftJoin("evaluation.training", "training")
.leftJoin("evaluation.assessment", "assessment")
.leftJoin("evaluation.portfolios", "portfolios")
.leftJoin("evaluation.performances", "performances")
.where("evaluation.id = :id", { id })
.select([
"evaluation.isEducationalQft",
"evaluation.isGovermantServiceHtr",
"evaluation.isOperatingExp",
"evaluation.isMinPeriodOfTenure",
"evaluation.isHaveSpecificQft",
"evaluation.isHaveProLicense",
"evaluation.isHaveMinPeriodOrHoldPos",
"evaluation.type",
"evaluation.prefix",
"evaluation.fullName",
"evaluation.position",
"evaluation.posNo",
"evaluation.oc",
"evaluation.salary",
"evaluation.positionLevel",
"evaluation.birthDate",
"evaluation.govAge",
"evaluation.experience",
"evaluation.detailAnnounceStep5Body",
"evaluation.detailAnnounceStep5Footer",
"evaluation.isUpdated",
"education.educationLevel",
"education.institute",
"education.isDate",
"education.startDate",
"education.endDate",
"education.finishDate",
"education.isEducation",
"education.degree",
"education.field",
"education.fundName",
"education.gpa",
"education.country",
"education.other",
"education.duration",
"education.durationYear",
"certificate.certificateType",
"certificate.issuer",
"certificate.certificateNo",
"certificate.issueDate",
"certificate.expireDate",
"salaries.date",
"salaries.amount",
"salaries.positionSalaryAmount",
"salaries.mouthSalaryAmount",
"salaries.position",
"salaries.posNo",
"salaries.salaryClass",
"salaries.salaryRef",
"salaries.refCommandNo",
"salaries.refCommandDate",
"salaries.salaryStatus",
"salaries.profileId",
"salaries.commandCode",
"salaries.commandNo",
"salaries.commandYear",
"salaries.commandDateAffect",
"salaries.commandDateSign",
"salaries.posNoAbb",
"salaries.positionName",
"salaries.positionType",
"salaries.positionLevel",
"salaries.positionLine",
"salaries.positionPathSide",
"salaries.positionExecutive",
"salaries.amountSpecial",
"salaries.orgRoot",
"salaries.orgChild1",
"salaries.orgChild2",
"salaries.orgChild3",
"salaries.orgChild4",
"salaries.remark",
"salaries.commandId",
"salaries.isGovernment",
"salaries.positionCee",
"salaries.commandName",
"salaries.posNumCodeSit",
"salaries.posNumCodeSitAbb",
"salaries.isEntry",
"training.name",
"training.topic",
"training.startDate",
"training.endDate",
"training.yearly",
"training.place",
"training.duration",
"training.department",
"training.numberOrder",
"training.dateOrder",
"assessment.date",
"assessment.point1Total",
"assessment.point1",
"assessment.point2Total",
"assessment.point2",
"assessment.pointSumTotal",
"assessment.pointSum",
"portfolios.name",
"portfolios.detail",
"performances.year",
"performances.type",
"performances.subject",
"performances.evaluationResult",
])
.orderBy("salaries.commandDateAffect", "DESC")
.getOne();
console.log(evaluation);
if (!evaluation) {
return "ไม่พบข้อมูล";
}
const dataEvaluation = {
isEducationalQft: evaluation.isEducationalQft,
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
isOperatingExp: evaluation.isOperatingExp,
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
isHaveSpecificQft: evaluation.isHaveSpecificQft,
isHaveProLicense: evaluation.isHaveProLicense,
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
type: evaluation.type,
prefix: evaluation.prefix,
fullName: evaluation.fullName,
position: evaluation.position,
posNo: evaluation.posNo,
oc: evaluation.oc,
salary: evaluation.salary,
positionLevel: evaluation.positionLevel,
birthDate: evaluation.birthDate,
govAge: evaluation.govAge,
experience: evaluation.experience,
detailAnnounceStep5Body: evaluation.detailAnnounceStep5Body,
detailAnnounceStep5Footer: evaluation.detailAnnounceStep5Footer,
isUpdated: evaluation.isUpdated,
educations: evaluation.education.map((education) => ({
educationLevel: education.educationLevel,
institute: education.institute,
isDate: education.isDate,
startDate: education.startDate,
endDate: education.endDate,
finishDate: education.finishDate,
isEducation: education.isEducation,
degree: education.degree,
field: education.field,
fundName: education.fundName,
gpa: education.gpa,
country: education.country,
other: education.other,
duration: education.duration,
durationYear: education.durationYear,
})),
certificates: evaluation.certificate.map((certificate) => ({
certificateType: certificate.certificateType,
issuer: certificate.issuer,
certificateNo: certificate.certificateNo,
issueDate: certificate.issueDate,
expireDate: certificate.expireDate,
})),
salaries: evaluation.salaries.map((salaries) => ({
date: salaries.date,
amount: salaries.amount,
positionSalaryAmount: salaries.positionSalaryAmount,
mouthSalaryAmount: salaries.mouthSalaryAmount,
position: salaries.position,
posNo: salaries.posNo,
salaryClass: salaries.salaryClass,
salaryRef: salaries.salaryRef,
refCommandNo: salaries.refCommandNo,
refCommandDate: salaries.refCommandDate,
salaryStatus: salaries.salaryStatus,
profileId: salaries.profileId,
commandCode: salaries.commandCode,
commandNo: salaries.commandNo,
commandYear: salaries.commandYear,
commandDateAffect: salaries.commandDateAffect,
commandDateSign: salaries.commandDateSign,
posNoAbb: salaries.posNoAbb,
positionName: salaries.positionName,
positionType: salaries.positionType,
positionLevel: salaries.positionLevel,
positionLine: salaries.positionLine,
positionPathSide: salaries.positionPathSide,
positionExecutive: salaries.positionExecutive,
amountSpecial: salaries.amountSpecial,
orgRoot: salaries.orgRoot,
orgChild1: salaries.orgChild1,
orgChild2: salaries.orgChild2,
orgChild3: salaries.orgChild3,
orgChild4: salaries.orgChild4,
remark: salaries.remark,
commandId: salaries.commandId,
isGovernment: salaries.isGovernment,
positionCee: salaries.positionCee,
commandName: salaries.commandName,
posNumCodeSit: salaries.posNumCodeSit,
posNumCodeSitAbb: salaries.posNumCodeSitAbb,
isEntry: salaries.isEntry,
})),
trainings: evaluation.training.map((training) => ({
name: training.name,
topic: training.topic,
startDate: training.startDate,
endDate: training.endDate,
yearly: training.yearly,
place: training.place,
duration: training.duration,
department: training.department,
numberOrder: training.numberOrder,
dateOrder: training.dateOrder,
})),
assessments: evaluation.assessment.map((assessment) => ({
date: assessment.date,
point1Total: assessment.point1Total,
point1: assessment.point1,
point2Total: assessment.point2Total,
point2: assessment.point2,
pointSumTotal: assessment.pointSumTotal,
pointSum: assessment.pointSum,
})),
portfolios: evaluation.portfolios.map((portfolio) => ({
name: portfolio.name,
detail: portfolio.detail,
})),
performances: evaluation.performances.map((performance) => ({
year: performance.year,
type: performance.type,
subject: performance.subject,
evaluationResult: performance.evaluationResult,
})),
// years: years
};
if (!dataEvaluation) {
return "ไม่พบข้อมูล";
}
return new HttpSuccess(dataEvaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลรายละเอียดตรวจสอบคุณสมบัติ
*
* @summary EV1_003 - รายละเอียดตรวจสอบคุณสมบัติ (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("admin/check-spec/{id}")
@Example([
{
isEducationalQft: "false",
isGovermantServiceHtr: "false",
isOperatingExp: "false",
isMinPeriodOfTenure: "false",
isHaveSpecificQft: "false",
isHaveProLicense: "false",
isHaveMinPeriodOrHoldPos: "false",
type: "EXPERT",
prefix: null,
fullname: null,
position: null,
posNo: null,
oc: null,
salary: null,
positionLevel: null,
birthDate: null,
govAge: null,
experience: null,
educations: [
{
educationLevel: "ต่ำกว่าปริญญาตรี",
institute: "มจธ",
isDate: true,
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
finishDate: "2023-12-14T00:00:00",
isEducation: false,
degree: "-",
field: "-",
fundName: "-",
gpa: "-",
country: "-",
other: "-",
duration: "-",
durationYear: 4,
},
],
certificates: [
{
certificateType: "-",
issuer: "-",
certificateNo: "-",
issueDate: "2023-12-14T00:00:00",
expireDate: "2023-12-14T00:00:00",
},
],
salaries: [
{
date: "2023-10-11T16:15:00.185384",
amount: 30220,
positionSalaryAmount: null,
mouthSalaryAmount: null,
position: "นักทรัพยากรบุคคล",
posNo: "สกจ.5",
salaryClass: null,
salaryRef: null,
refCommandNo: null,
refCommandDate: null,
salaryStatus: null,
},
],
trainings: [
{
name: "-",
topic: "-",
startDate: "2023-12-14T00:00:00",
endDate: "2023-12-14T00:00:00",
yearly: 2023,
place: "-",
duration: "-",
department: "-",
numberOrder: "-",
dateOrder: "2023-12-14T02:54:30.448",
},
],
assessments: [
{
date: "2023-12-14T00:00:00",
point1Total: 60,
point1: 46,
point2Total: 40,
point2: 34,
pointSumTotal: 100,
pointSum: 80,
},
],
},
])
async checkSpecGetByAdmin(@Request() request: RequestWithUser, @Path() id: string) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.leftJoin("evaluation.education", "education")
.leftJoin("evaluation.certificate", "certificate")
.leftJoin("evaluation.salaries", "salaries")
.leftJoin("evaluation.training", "training")
.leftJoin("evaluation.assessment", "assessment")
.leftJoin("evaluation.portfolios", "portfolios")
.leftJoin("evaluation.performances", "performances")
.where("evaluation.id = :id", { id })
.select([
"evaluation.isEducationalQft",
"evaluation.isGovermantServiceHtr",
"evaluation.isOperatingExp",
"evaluation.isMinPeriodOfTenure",
"evaluation.isHaveSpecificQft",
"evaluation.isHaveProLicense",
"evaluation.isHaveMinPeriodOrHoldPos",
"evaluation.type",
"evaluation.prefix",
"evaluation.fullName",
"evaluation.position",
"evaluation.posNo",
"evaluation.oc",
"evaluation.salary",
"evaluation.positionLevel",
"evaluation.birthDate",
"evaluation.govAge",
"evaluation.experience",
"evaluation.detailAnnounceStep5Body",
"evaluation.detailAnnounceStep5Footer",
"evaluation.isUpdated",
"education.educationLevel",
"education.institute",
"education.isDate",
"education.startDate",
"education.endDate",
"education.finishDate",
"education.isEducation",
"education.degree",
"education.field",
"education.fundName",
"education.gpa",
"education.country",
"education.other",
"education.duration",
"education.durationYear",
"certificate.certificateType",
"certificate.issuer",
"certificate.certificateNo",
"certificate.issueDate",
"certificate.expireDate",
"salaries.date",
"salaries.amount",
"salaries.positionSalaryAmount",
"salaries.mouthSalaryAmount",
"salaries.position",
"salaries.posNo",
"salaries.salaryClass",
"salaries.salaryRef",
"salaries.refCommandNo",
"salaries.refCommandDate",
"salaries.salaryStatus",
"salaries.profileId",
"salaries.commandCode",
"salaries.commandNo",
"salaries.commandYear",
"salaries.commandDateAffect",
"salaries.commandDateSign",
"salaries.posNoAbb",
"salaries.positionName",
"salaries.positionType",
"salaries.positionLevel",
"salaries.positionLine",
"salaries.positionPathSide",
"salaries.positionExecutive",
"salaries.amountSpecial",
"salaries.orgRoot",
"salaries.orgChild1",
"salaries.orgChild2",
"salaries.orgChild3",
"salaries.orgChild4",
"salaries.remark",
"salaries.commandId",
"salaries.isGovernment",
"salaries.positionCee",
"salaries.commandName",
"salaries.posNumCodeSit",
"salaries.posNumCodeSitAbb",
"salaries.isEntry",
"training.name",
"training.topic",
"training.startDate",
"training.endDate",
"training.yearly",
"training.place",
"training.duration",
"training.department",
"training.numberOrder",
"training.dateOrder",
"assessment.date",
"assessment.point1Total",
"assessment.point1",
"assessment.point2Total",
"assessment.point2",
"assessment.pointSumTotal",
"assessment.pointSum",
"portfolios.name",
"portfolios.detail",
"performances.year",
"performances.type",
"performances.subject",
"performances.evaluationResult",
])
.orderBy("salaries.commandDateAffect", "DESC")
.getOne();
if (!evaluation) {
return "ไม่พบข้อมูล";
}
const dataEvaluation = {
isEducationalQft: evaluation.isEducationalQft,
isGovermantServiceHtr: evaluation.isGovermantServiceHtr,
isOperatingExp: evaluation.isOperatingExp,
isMinPeriodOfTenure: evaluation.isMinPeriodOfTenure,
isHaveSpecificQft: evaluation.isHaveSpecificQft,
isHaveProLicense: evaluation.isHaveProLicense,
isHaveMinPeriodOrHoldPos: evaluation.isHaveMinPeriodOrHoldPos,
type: evaluation.type,
prefix: evaluation.prefix,
fullName: evaluation.fullName,
position: evaluation.position,
posNo: evaluation.posNo,
oc: evaluation.oc,
salary: evaluation.salary,
positionLevel: evaluation.positionLevel,
birthDate: evaluation.birthDate,
govAge: evaluation.govAge,
experience: evaluation.experience,
detailAnnounceStep5Body: evaluation.detailAnnounceStep5Body,
detailAnnounceStep5Footer: evaluation.detailAnnounceStep5Footer,
isUpdated: evaluation.isUpdated,
educations: evaluation.education.map((education) => ({
educationLevel: education.educationLevel,
institute: education.institute,
isDate: education.isDate,
startDate: education.startDate,
endDate: education.endDate,
finishDate: education.finishDate,
isEducation: education.isEducation,
degree: education.degree,
field: education.field,
fundName: education.fundName,
gpa: education.gpa,
country: education.country,
other: education.other,
duration: education.duration,
durationYear: education.durationYear,
})),
certificates: evaluation.certificate.map((certificate) => ({
certificateType: certificate.certificateType,
issuer: certificate.issuer,
certificateNo: certificate.certificateNo,
issueDate: certificate.issueDate,
expireDate: certificate.expireDate,
})),
salaries: evaluation.salaries.map((salaries) => ({
date: salaries.date,
amount: salaries.amount,
positionSalaryAmount: salaries.positionSalaryAmount,
mouthSalaryAmount: salaries.mouthSalaryAmount,
position: salaries.position,
posNo: salaries.posNo,
salaryClass: salaries.salaryClass,
salaryRef: salaries.salaryRef,
refCommandNo: salaries.refCommandNo,
refCommandDate: salaries.refCommandDate,
salaryStatus: salaries.salaryStatus,
profileId: salaries.profileId,
commandCode: salaries.commandCode,
commandNo: salaries.commandNo,
commandYear: salaries.commandYear,
commandDateAffect: salaries.commandDateAffect,
commandDateSign: salaries.commandDateSign,
posNoAbb: salaries.posNoAbb,
positionName: salaries.positionName,
positionType: salaries.positionType,
positionLevel: salaries.positionLevel,
positionLine: salaries.positionLine,
positionPathSide: salaries.positionPathSide,
positionExecutive: salaries.positionExecutive,
amountSpecial: salaries.amountSpecial,
orgRoot: salaries.orgRoot,
orgChild1: salaries.orgChild1,
orgChild2: salaries.orgChild2,
orgChild3: salaries.orgChild3,
orgChild4: salaries.orgChild4,
remark: salaries.remark,
commandId: salaries.commandId,
isGovernment: salaries.isGovernment,
positionCee: salaries.positionCee,
commandName: salaries.commandName,
posNumCodeSit: salaries.posNumCodeSit,
posNumCodeSitAbb: salaries.posNumCodeSitAbb,
isEntry: salaries.isEntry,
})),
trainings: evaluation.training.map((training) => ({
name: training.name,
topic: training.topic,
startDate: training.startDate,
endDate: training.endDate,
yearly: training.yearly,
place: training.place,
duration: training.duration,
department: training.department,
numberOrder: training.numberOrder,
dateOrder: training.dateOrder,
})),
assessments: evaluation.assessment.map((assessment) => ({
date: assessment.date,
point1Total: assessment.point1Total,
point1: assessment.point1,
point2Total: assessment.point2Total,
point2: assessment.point2,
pointSumTotal: assessment.pointSumTotal,
pointSum: assessment.pointSum,
})),
portfolios: evaluation.portfolios.map((portfolio) => ({
name: portfolio.name,
detail: portfolio.detail,
})),
performances: evaluation.performances.map((performance) => ({
year: performance.year,
type: performance.type,
subject: performance.subject,
evaluationResult: performance.evaluationResult,
})),
};
if (!dataEvaluation) {
return "ไม่พบข้อมูล";
}
return new HttpSuccess(dataEvaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกจัดเตรียมเอกสาร
*
* @summary EV1_017 - บันทึกจัดเตรียมเอกสาร (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("prepare-doc-v1/approve/{id}")
async EV1_017(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "CHECK_DOC_V1") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("CHECK_DOC_V1")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "CHECK_DOC_V1";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกจัดเตรียมเอกสารเล่ม 1`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกจัดเตรียมเอกสารเล่ม 1`,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ย้อนกลับจัดเตรียมเอกสาร
*
* @summary EV1_018 - ย้อนกลับจัดเตรียมเอกสาร (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("prepare-doc-v1/reject/{id}")
async EV1_018(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "CHECK_SPEC") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("CHECK_SPEC")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "CHECK_SPEC";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกตรวจสอบจัดเตรียมเอกสาร
*
* @summary EV1_020 - บันทึกตรวจสอบจัดเตรียมเอกสาร (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("check-doc-v1/approve/{id}")
async EV1_020(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "WAIT_CHECK_DOC_V1") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("WAIT_CHECK_DOC_V1")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "WAIT_CHECK_DOC_V1";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
let _director: any;
await new CallAPI()
.PostData(request, "/org/workflow/find/director-with-keycloak/SYS_EVA_REQ", {
refId: [evaluation.userId],
})
.then((x) => {
_director = x;
})
.catch((x) => {});
await Promise.all(
_director.map((director:any) => {
return new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
receiverUserId: director.keycloak,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {
})
.catch((x) => {});
})
);
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ย้อนกลับตรวจสอบจัดเตรียมเอกสาร
*
* @summary EV1_021 - ย้อนกลับตรวจสอบจัดเตรียมเอกสาร (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("check-doc-v1/reject/{id}")
async EV1_021(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "PREPARE_DOC_V1") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("PREPARE_DOC_V1")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "PREPARE_DOC_V1";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกตรวจสอบเอกสาร
*
* @summary EV1_023 - อนุมัติตรวจสอบเอกสาร (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("doc1/approve/{id}")
async EV1_023(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "ANNOUNCE_WEB") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("ANNOUNCE_WEB")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "ANNOUNCE_WEB";
evaluation.dateAnnounce = new Date();
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "แบบประเมินของคุณอนุมัติตรวจสอบเอกสารเล่ม 1",
body: "แบบประเมินของคุณอนุมัติตรวจสอบเอกสารเล่ม 1",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ไม่อนุมัติตรวจสอบเอกสาร
*
* @summary EV1_024 - ไม่อนุมัติตรวจสอบเอกสาร (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("doc1/reject/{id}")
async EV1_024(
@Path() id: string,
@Body() body: { reason: string },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "CHECK_DOC_V1") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("CHECK_DOC_V1")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "CHECK_DOC_V1";
evaluation.reason = body.reason;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "แบบประเมินของคุณไม่อนุมัติตรวจสอบเอกสารเล่ม 1",
body: "แบบประเมินของคุณไม่อนุมัติตรวจสอบเอกสารเล่ม 1",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 2
*
* @summary EV1_028 - บันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 2 (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("check-doc-v1/{id}")
async EV1_028(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "WAIT_CHECK_DOC_V2") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("WAIT_CHECK_DOC_V2")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "WAIT_CHECK_DOC_V2";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 2`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 2`,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกจัดเตรียมเอกสารเล่ม 2
*
* @summary EV1_029 - บันทึกจัดเตรียมเอกสารเล่ม 2 (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("prepare-doc-v2/approve/{id}")
async EV1_029(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "CHECK_DOC_V2") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("CHECK_DOC_V2")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "CHECK_DOC_V2";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกจัดเตรียมเอกสารเล่ม 2`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกจัดเตรียมเอกสารเล่ม 2`,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แก้ไข template ประกาศคัดเลือก
*
* @summary แก้ไข template ประกาศคัดเลือก (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("edit-announce-template/{id}")
async editAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser, @Body() body: {detailBody: string, detailFooter: string}) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const before = structuredClone(evaluation);
evaluation.detailAnnounceStep5Body = body.detailBody;
evaluation.detailAnnounceStep5Footer = body.detailFooter;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกแจ้งผลการประกาศคัดเลือก
*
* @summary EV1_042 - บันทึกแจ้งผลการประกาศคัดเลือก (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("announce/{id}")
async EV1_042(@Path() id: string, @Request() request: RequestWithUser) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "PREPARE_DOC_V2") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("PREPARE_DOC_V2")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "PREPARE_DOC_V2";
evaluation.subjectDoc2 = evaluation.subject;
evaluation.authorDoc2 = evaluation.author;
evaluation.assignedPosition = evaluation.position;
evaluation.commanderFullnameDoc2 = evaluation.commanderFullname;
evaluation.commanderPositionDoc2 = evaluation.commanderPosition;
evaluation.commanderAboveFullnameDoc2 = evaluation.commanderAboveFullname;
evaluation.commanderAbovePositionDoc2 = evaluation.commanderAbovePosition;
evaluation.commanderOrgDoc2 = evaluation.commanderOrg;
evaluation.commanderOrgOldDoc2 = evaluation.commanderOrgOld;
evaluation.commanderPositionOldDoc2 = evaluation.commanderPositionOld;
evaluation.commanderAboveOrgDoc2 = evaluation.commanderAboveOrg;
evaluation.commanderAboveOrgOldDoc2 = evaluation.commanderAboveOrgOld;
evaluation.commanderAbovePositionOldDoc2 = evaluation.commanderAbovePositionOld;
evaluation.datePrepareDoc2 = new Date();
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "เจ้าหน้าที่แจ้งผลประกาศคัดเลือก",
body: "เจ้าหน้าที่แจ้งผลประกาศคัดเลือก",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ย้อนกลับจัดเตรียมเอกสารเล่ม 2
*
* @summary EV1_030 - ย้อนกลับจัดเตรียมเอกสารเล่ม 2 (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("prepare-doc-v2/reject/{id}")
async EV1_030(@Path() id: string, @Request() request: RequestWithUser) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "PREPARE_DOC_V2") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("PREPARE_DOC_V2")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "PREPARE_DOC_V2";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกตรวจสอบเอกสารเล่ม 2
*
* @summary EV1_031 - อนุมัติตรวจสอบเอกสารเล่ม 2 (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("wait-check-doc-v2/{id}")
async EV1_031(@Path() id: string, @Request() request: RequestWithUser) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "DONE") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("DONE")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "DONE";
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "แบบประเมินของคุณอนุมัติตรวจสอบเอกสารเล่ม 2",
body: "แบบประเมินของคุณอนุมัติตรวจสอบเอกสารเล่ม 2",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ไม่อนุมัติตรวจสอบเอกสารเล่ม 2
*
* @summary EV1_032 - ไม่อนุมัติตรวจสอบเอกสารเล่ม 2 (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("doc2/reject/{id}")
async EV1_032(
@Path() id: string,
@Body() body: { reason: string },
@Request() request: RequestWithUser,
) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (evaluation.step != "CHECK_DOC_V2") {
const evaluationLogs = new EvaluationLogs();
const _null: any = null;
evaluationLogs.step = (await ConvertToThaiStep("CHECK_DOC_V2")) ?? _null;
evaluationLogs.createdUserId = request.user.sub;
evaluationLogs.createdFullName = request.user.name;
evaluationLogs.createdAt = new Date();
evaluationLogs.lastUpdateUserId = request.user.sub;
evaluationLogs.lastUpdateFullName = request.user.name;
evaluationLogs.lastUpdatedAt = new Date();
evaluationLogs.evaluation = evaluation;
await this.evaluationLogsRepository.save(evaluationLogs, { data: request });
setLogDataDiff(request, { before: null, after: evaluationLogs });
}
const before = structuredClone(evaluation);
evaluation.step = "CHECK_DOC_V2";
evaluation.reason = body.reason;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "แบบประเมินของคุณไม่อนุมัติตรวจสอบเอกสารเล่ม 2",
body: "แบบประเมินของคุณไม่อนุมัติตรวจสอบเอกสารเล่ม 2",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ประวัติการเปลี่ยนสถานะรายการคำขอประเมิน
*
* @summary EV1_033 - ประวัติการเปลี่ยนสถานะ (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("step-history/{id}")
async StepHistory(@Path() id: string) {
try {
const stepHistory = await this.evaluationLogsRepository.find({
where: {
evaluationId: id,
},
select: ["step", "lastUpdateFullName", "lastUpdatedAt"],
order: {
lastUpdatedAt: "ASC",
},
});
return new HttpSuccess(stepHistory);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API เลือกกรรมการรายการคำขอประเมิน
*
* @summary EV1_034 - เลือกกรรมการ (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("choose-directors/{id}")
async ChooseDirectors(
@Path() id: string,
@Body() body: { directors: string[] },
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_EVA_INFO");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
const before = structuredClone(evaluation);
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (!evaluation.directors) {
evaluation.directors = [];
}
body.directors.forEach(async (directorId) => {
const director = await this.directorRepository.findOne({ where: { id: directorId } });
if (director != null) evaluation.directors.push(director);
});
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "แบบประเมินของคุณมีการเลือกกรรมการประเมิน",
body: "แบบประเมินของคุณมีการเลือกกรรมการประเมิน",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API เลือกการประชุมรายการคำขอประเมิน
*
* @summary EV1_035 - เลือกประชุม (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("choose-meetings/{id}")
async ChooseMeetings(
@Path() id: string,
@Body() body: { meetings: string[] },
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
const before = structuredClone(evaluation);
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
if (!evaluation.meetings) {
evaluation.meetings = [];
}
body.meetings.forEach(async (meetingId) => {
const meeting = await this.meetingRepository.findOne({ where: { id: meetingId } });
if (meeting != null) evaluation.meetings.push(meeting);
});
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: "มีการประชุมกรรมการประเมินผล",
body: "มีการประชุมกรรมการประเมินผล",
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แสดงข้อมูลกรรมการและการประชุม
*
* @summary EV1_036 - แสดงกรรมการและการประชุม (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("director-meeting/{id}")
async DirectorAndMeeting(@Request() request: RequestWithUser, @Path() id: string) {
try {
await new permission().PermissionList(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
relations: ["directors", "meetings"],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const directors = evaluation.directors.map((director) => ({
id: director.id,
prefix: director.prefix,
firstName: director.firstName,
lastName: director.lastName,
position: director.position,
positionName: null,
email: director.email,
phone: director.phone,
duty: director.duty,
}));
const meetings = evaluation.meetings.map((meeting) => ({
id: meeting.id,
dateStart: meeting.dateStart,
dateEnd: meeting.dateEnd,
result: meeting.result,
duration: meeting.duration,
round: meeting.round,
title: meeting.title,
}));
return new HttpSuccess({ directors, meetings });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ช่วงเวลาประเมิน
*
* @summary EV1_037 - แสดงช่วงเวลาประเมิน (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("check-date/{id}")
async CheckRangeDate(@Path() id: string) {
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const responseData = {
dateStartAnnounce:
evaluation.dateAnnounce == null ? null : new Date(evaluation.dateAnnounce.toString()),
dateEndAnnounce:
evaluation.dateAnnounce == null
? null
: new Date(evaluation.dateAnnounce.setDate(evaluation.dateAnnounce.getDate() + 30)),
dateStartPrepareDoc2:
evaluation.datePrepareDoc2 == null
? null
: new Date(evaluation.datePrepareDoc2.toString()),
dateEndPrepareDoc2:
evaluation.datePrepareDoc2 == null
? null
: new Date(
evaluation.datePrepareDoc2.setMonth(evaluation.datePrepareDoc2.getMonth() + 6),
),
};
return new HttpSuccess(responseData);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ช่วงเวลาประเมิน
*
* @summary EV1_037 - แสดงช่วงเวลาประเมิน (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("admin/check-date/{id}")
async CheckRangeDateByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const responseData = {
dateStartAnnounce:
evaluation.dateAnnounce == null ? null : new Date(evaluation.dateAnnounce.toString()),
dateEndAnnounce:
evaluation.dateAnnounce == null
? null
: new Date(evaluation.dateAnnounce.setDate(evaluation.dateAnnounce.getDate() + 30)),
dateStartPrepareDoc2:
evaluation.datePrepareDoc2 == null
? null
: new Date(evaluation.datePrepareDoc2.toString()),
dateEndPrepareDoc2:
evaluation.datePrepareDoc2 == null
? null
: new Date(
evaluation.datePrepareDoc2.setMonth(evaluation.datePrepareDoc2.getMonth() + 6),
),
};
return new HttpSuccess(responseData);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ตอบกลับข้อความให้ admin
*
* @summary EV1_038 - ตอบกลับข้อความให้ admin (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("contact/admin/{id}")
async SendNotiAdmin(
@Path() id: string,
@Body() body: { subject: string; body: string },
@Request() request: RequestWithUser,
) {
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: body.subject,
body: body.body,
receiverUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ตอบกลับข้อความให้ user
*
* @summary EV1_039 - ตอบกลับข้อความให้ user (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("contact/user/{id}")
async SendNotiUser(
@Path() id: string,
@Body() body: { subject: string; body: string },
@Request() request: RequestWithUser,
) {
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
await new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: body.subject,
body: body.body,
receiverUserId: evaluation.userId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แสดงข้อมูลผู้เซ็นเอกสารเล่ม 1
*
* @summary EV1_040 - แสดงข้อมูลผู้เซ็นเอกสารเล่ม 1 (USER)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("doc1-signer/{id}")
async DocumentSigner1(@Path() id: string, @Request() request: RequestWithUser) {
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"author",
"subject",
"commanderFullname",
"commanderOrg",
"commanderOrgOld",
"commanderPosition",
"commanderPositionOld",
"commanderAboveFullname",
"commanderAboveOrg",
"commanderAboveOrgOld",
"commanderAbovePosition",
"commanderAbovePositionOld",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แสดงข้อมูลผู้เซ็นเอกสารเล่ม 1
*
* @summary EV1_040 - แสดงข้อมูลผู้เซ็นเอกสารเล่ม 1 (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("admin/doc1-signer/{id}")
async DocumentSigner1ByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"author",
"subject",
"commanderFullname",
"commanderOrg",
"commanderOrgOld",
"commanderPosition",
"commanderPositionOld",
"commanderAboveFullname",
"commanderAboveOrg",
"commanderAboveOrgOld",
"commanderAbovePosition",
"commanderAbovePositionOld",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แสดงข้อมูลผู้เซ็นเอกสารเล่ม 2
*
* @summary EV1_041 - แสดงข้อมูลผู้เซ็นเอกสารเล่ม 2 (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("doc2-signer/{id}")
async DocumentSigner2(@Path() id: string) {
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"authorDoc2",
"subjectDoc2",
"assignedPosition",
"commanderFullnameDoc2",
"commanderOrgDoc2",
"commanderOrgOldDoc2",
"commanderPositionDoc2",
"commanderPositionOldDoc2",
"commanderAboveFullnameDoc2",
"commanderAboveOrgDoc2",
"commanderAboveOrgOldDoc2",
"commanderAbovePositionDoc2",
"commanderAbovePositionOldDoc2",
"evaluationResult",
"isUpdated",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API แสดงข้อมูลผู้เซ็นเอกสารเล่ม 2
*
* @summary EV1_041 - แสดงข้อมูลผู้เซ็นเอกสารเล่ม 2 (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("admin/doc2-signer/{id}")
async DocumentSigner2ByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"authorDoc2",
"subjectDoc2",
"assignedPosition",
"commanderFullnameDoc2",
"commanderOrgDoc2",
"commanderOrgOldDoc2",
"commanderPositionDoc2",
"commanderPositionOldDoc2",
"commanderAboveFullnameDoc2",
"commanderAboveOrgDoc2",
"commanderAboveOrgOldDoc2",
"commanderAbovePositionDoc2",
"commanderAbovePositionOldDoc2",
"evaluationResult",
"isUpdated",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกชื่อผลงาน ชื่อเจ้าของผลงาน และชื่อคณะกรรมการ
*
* @summary บันทึกชื่อผลงาน ชื่อเจ้าของผลงาน และชื่อคณะกรรมการ (User)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("update-author-director/{id}")
@Example([
{
author: "string",
subject: "string",
commanderFullname: "string",
commanderPosition: "string",
commanderAboveFullname: "string",
commanderAbovePosition: "string",
},
])
async updateAuthorDirector(
@Path() id: string,
@Body()
body: {
author: string;
subject: string[];
commanderFullname: string;
commanderOrg?: string;
commanderOrgOld?: string;
commanderPosition: string;
commanderPositionOld?: string;
commanderAboveFullname: string;
commanderAboveOrg?: string;
commanderAboveOrgOld?: string;
commanderAbovePosition: string;
commanderAbovePositionOld?: string;
},
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const _null:any = null;
evaluation.author = body.author;
evaluation.subject = body.subject;
evaluation.commanderFullname = body.commanderFullname;
evaluation.commanderOrg = body.commanderOrg??_null;
evaluation.commanderOrgOld = body.commanderOrgOld??_null;
evaluation.commanderPosition = body.commanderPosition;
evaluation.commanderPositionOld = body.commanderPositionOld??_null;
evaluation.commanderAboveFullname = body.commanderAboveFullname;
evaluation.commanderAboveOrg = body.commanderAboveOrg??_null;
evaluation.commanderAboveOrgOld = body.commanderAboveOrgOld??_null;
evaluation.commanderAbovePosition = body.commanderAbovePosition;
evaluation.commanderAbovePositionOld = body.commanderAbovePositionOld??_null;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
const before = structuredClone(evaluation);
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API บันทึกชื่อผลงาน ชื่อเจ้าของผลงาน และชื่อคณะกรรมการ2
*
* @summary บันทึกชื่อผลงาน ชื่อเจ้าของผลงาน และชื่อคณะกรรมการ2 (User)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Put("update-author-director2/{id}")
@Example([
{
authorDoc2: "string",
subjectDoc2: "string",
assignedPosition: "string",
commanderFullnameDoc2: "string",
commanderPositionDoc2: "string",
commanderAboveFullnameDoc2: "string",
commanderAbovePositionDoc2: "string",
},
])
async updateAuthorDirector2(
@Path() id: string,
@Body()
body: {
authorDoc2: string;
subjectDoc2: string[];
assignedPosition: string;
commanderFullnameDoc2: string;
commanderPositionDoc2: string;
commanderAboveFullnameDoc2: string;
commanderAbovePositionDoc2: string;
commanderOrgDoc2?: string;
commanderOrgOldDoc2?: string;
commanderPositionOldDoc2?: string;
commanderAboveOrgDoc2?: string;
commanderAboveOrgOldDoc2?: string;
commanderAbovePositionOldDoc2?: string;
},
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const _null:any = null;
evaluation.authorDoc2 = body.authorDoc2;
evaluation.subjectDoc2 = body.subjectDoc2;
evaluation.assignedPosition = body.assignedPosition;
evaluation.commanderFullnameDoc2 = body.commanderFullnameDoc2;
evaluation.commanderOrgDoc2 = body.commanderOrgDoc2??_null;
evaluation.commanderOrgOldDoc2 = body.commanderOrgOldDoc2??_null;
evaluation.commanderPositionDoc2 = body.commanderPositionDoc2;
evaluation.commanderPositionOldDoc2 = body.commanderPositionOldDoc2??_null;
evaluation.commanderAboveFullnameDoc2 = body.commanderAboveFullnameDoc2;
evaluation.commanderAboveOrgDoc2 = body.commanderAboveOrgDoc2??_null;
evaluation.commanderAboveOrgOldDoc2 = body.commanderAboveOrgOldDoc2??_null;
evaluation.commanderAbovePositionDoc2 = body.commanderAbovePositionDoc2;
evaluation.commanderAbovePositionOldDoc2 = body.commanderAbovePositionOldDoc2??_null;
evaluation.isUpdated = true;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
const before = structuredClone(evaluation);
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API ลบแบบประเมิน (USER)
*
* @summary EV1_037 - ลบแบบประเมิน (USER)
*
* @param {string} id id การประเมิน
*/
@Delete("{id}")
async delete_evaluation(id: string, @Request() request: RequestWithUser) {
try {
// await new permission().PermissionDelete(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
relations: ["meetings", "directors"],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
evaluation.meetings;
if (["CHECK_SPEC", "PREPARE_DOC_V1", "CHECK_DOC_V1"].includes(evaluation.step)) {
await this.educationRepository.delete({ evaluationId: id });
await this.certificateRepository.delete({ evaluationId: id });
await this.salaryRepository.delete({ evaluationId: id });
await this.trainingRepository.delete({ evaluationId: id });
await this.assessmentRepository.delete({ evaluationId: id });
await this.portfolioRepository.delete({ evaluationId: id });
await this.performanceRepository.delete({ evaluationId: id });
await this.evaluationLogsRepository.delete({ evaluationId: id });
await Promise.all(
evaluation.meetings.map((meeting) =>
this.meetingRepository.remove(meeting, { data: request }),
),
);
await Promise.all(
evaluation.directors.map((director) =>
this.directorRepository.remove(director, { data: request }),
),
);
await this.evaluationRepository.delete({ id });
return new HttpSuccess();
} else {
throw new HttpError(
HttpStatusCode.BAD_REQUEST,
"ไม่สามารถลบข้อมูลในสถานะ" + "'" + ConvertToThaiStep(evaluation.step) + "'" + "ได้",
);
}
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* ดึงข้อมูลรายละเอียด step การขอประเมิน
*
* @summary EV1_002 - รายละเอียด step การขอประเมิน (ADMIN)
*
* @param {string} id id ข้อมูลการประเมิน
*/
@Get("check/admin/{id}")
@Example([
{
step: "string",
},
])
async checkByAdmin(@Request() request: RequestWithUser, @Path() id: string) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: ["step"],
});
if (!evaluation) {
return "ไม่พบข้อมูล";
}
return new HttpSuccess(evaluation);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
}