hrms-api-eva/src/controllers/EvaluationController.ts

2813 lines
104 KiB
TypeScript
Raw Normal View History

2024-12-04 17:25:34 +07:00
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";
2024-12-14 01:04:30 +07:00
import { ConvertThaiToType, ConvertToThaiStep, ConvertToThaiType } from "../services/storage";
2024-12-04 17:25:34 +07:00
import { Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
2025-04-08 16:40:11 +07:00
import Extension from "../interfaces/extension";
2024-12-04 17:25:34 +07:00
@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 directorRepository = AppDataSource.getRepository(Director);
private meetingRepository = AppDataSource.getRepository(Meeting);
2024-12-19 23:35:15 +07:00
/**
* API
*
* @summary
*
*/
@Get("clear-db")
async ClearDb() {
return new HttpSuccess();
}
2024-12-04 17:25:34 +07:00
/**
*
*
* @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[];
},
) {
2025-03-14 18:14:43 +07:00
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
2025-03-17 10:08:23 +07:00
? `evaluation.rootDnaId IN (:...root)`
: `evaluation.rootDnaId is null`
2025-03-14 18:14:43 +07:00
: "1=1",
{
root: _data.root,
},
)
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
2025-03-17 10:08:23 +07:00
? `evaluation.child1DnaId IN (:...child1)`
: `evaluation.child1DnaId is null`
2025-03-14 18:14:43 +07:00
: "1=1",
{
child1: _data.child1,
},
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
2025-03-17 10:08:23 +07:00
? `evaluation.child2DnaId IN (:...child2)`
: `evaluation.child2DnaId is null`
2025-03-14 18:14:43 +07:00
: "1=1",
{
child2: _data.child2,
},
)
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
2025-03-17 10:08:23 +07:00
? `evaluation.child3DnaId IN (:...child3)`
: `evaluation.child3DnaId is null`
2025-03-14 18:14:43 +07:00
: "1=1",
{
child3: _data.child3,
},
)
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
2025-03-17 10:08:23 +07:00
? `evaluation.child4DnaId IN (:...child4)`
: `evaluation.child4DnaId is null`
2025-03-14 18:14:43 +07:00
: "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();
2024-12-04 17:25:34 +07:00
2025-03-14 18:14:43 +07:00
return new HttpSuccess({ data: evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
2024-12-04 17:25:34 +07:00
}
/**
* 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[];
},
) {
2025-03-14 17:22:25 +07:00
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,
}));
2024-12-04 17:25:34 +07:00
2025-03-14 17:22:25 +07:00
return new HttpSuccess({ data: _evaluation, total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
2024-12-04 17:25:34 +07:00
}
/**
*
*
* @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 } }) {
2025-03-14 17:22:25 +07:00
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);
}
2024-12-04 17:25:34 +07:00
}
/**
* step
*
* @summary EV1_002 - step (USER)
*
* @param {string} id id
*/
@Get("check/{id}")
@Example([
{
step: "string",
},
])
async check(@Request() request: RequestWithUser, @Path() id: string) {
2025-03-14 17:22:25 +07:00
try {
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: ["step"],
});
2024-12-04 17:25:34 +07:00
2025-03-14 17:22:25 +07:00
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);
2024-12-04 17:25:34 +07:00
}
}
/**
*
*
* @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,
2025-01-06 14:41:25 +07:00
root: null,
orgRootId: null,
2024-12-04 17:25:34 +07:00
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 evaluation = Object.assign(new Evaluation(), requestBody);
if (!evaluation) {
return `not found data`;
}
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();
2024-12-04 17:25:34 +07:00
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;
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
const _null: any = null;
//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
2025-04-08 16:40:11 +07:00
// 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) {
2024-12-04 17:25:34 +07:00
requestBody.salaries.forEach(async (salary) => {
const salaries = new Salary();
2025-04-08 16:40:11 +07:00
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;
2024-12-04 17:25:34 +07:00
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();
2025-04-08 16:40:11 +07:00
2024-12-04 17:25:34 +07:00
await this.salaryRepository.save(salaries, { data: request });
setLogDataDiff(request, { before, after: salaries });
});
2025-04-08 16:40:11 +07:00
}
2024-12-04 17:25:34 +07:00
//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 });
});
//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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
*
*
*/
@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;
2025-03-17 10:08:23 +07:00
evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId;
2024-12-04 17:25:34 +07:00
})
.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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
2024-12-20 10:24:50 +07:00
/**
* API
*
* @summary
*
* @param {string} id id
*/
2024-12-20 11:08:41 +07:00
@Put("updateEvaluationResult/{id}")
async updateEvaluationResult(
2024-12-20 10:24:50 +07:00
@Request() request: RequestWithUser,
@Path() id: string,
@Body() body: { result: string },
) {
try {
2024-12-20 11:08:41 +07:00
const result = body.result.toUpperCase();
if (result !== "PASS" && result !== "NOTPASS" && result !== "PENDING") {
2024-12-20 10:24:50 +07:00
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผลลัพธ์ดังกล่าว");
}
const evaluation = await this.evaluationRepository.findOne({
where: { id },
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
2025-01-20 17:45:14 +07:00
evaluation.evaluationResult = result;
2024-12-20 10:24:50 +07:00
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-20 10:24:50 +07:00
}
}
2024-12-04 17:25:34 +07:00
/**
*
*
*/
@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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
*
*
* @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) {
2025-03-14 17:22:25 +07:00
try {
2025-04-08 16:40:11 +07:00
// 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()),
// };
2025-03-14 17:22:25 +07:00
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")
.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",
"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",
2025-04-08 16:40:11 +07:00
"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",
2025-03-14 17:22:25 +07:00
"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",
])
.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,
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,
2025-04-08 16:40:11 +07:00
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,
2025-03-14 17:22:25 +07:00
})),
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,
})),
2025-04-08 16:40:11 +07:00
// years: years
2025-03-14 17:22:25 +07:00
};
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);
2024-12-04 17:25:34 +07:00
}
}
/**
*
*
* @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) {
2025-03-14 17:22:25 +07:00
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")
.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",
"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",
"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",
])
.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,
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,
})),
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,
})),
};
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);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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 });
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* API
*
* @summary EV1_042 - (ADMIN)
*
* @param {string} id id
*/
@Put("announce/{id}")
async EV1_042(@Path() id: string, @Request() request: RequestWithUser) {
try {
2025-03-14 17:22:25 +07:00
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
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";
2025-01-22 10:13:59 +07:00
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;
2024-12-04 17:25:34 +07:00
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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 {
2025-03-14 17:22:25 +07:00
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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 {
2025-03-14 17:22:25 +07:00
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* API
*
* @summary EV1_036 - (ADMIN)
*
* @param {string} id id
*/
@Get("director-meeting/{id}")
async DirectorAndMeeting(@Request() request: RequestWithUser, @Path() id: string) {
try {
2025-03-14 17:22:25 +07:00
await new permission().PermissionList(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
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,
}));
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* API
*
* @summary EV1_037 - (ADMIN)
*
* @param {string} id id
*/
@Get("admin/check-date/{id}")
async CheckRangeDateByAdmin(@Path() id: string, @Request() request: RequestWithUser) {
try {
2025-03-14 17:22:25 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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",
"commanderPosition",
"commanderAboveFullname",
"commanderAbovePosition",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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 {
2025-03-14 17:22:25 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"author",
"subject",
"commanderFullname",
"commanderPosition",
"commanderAboveFullname",
"commanderAbovePosition",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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",
"commanderPositionDoc2",
"commanderAboveFullnameDoc2",
"commanderAbovePositionDoc2",
2025-01-06 16:19:16 +07:00
"evaluationResult",
2024-12-04 17:25:34 +07:00
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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 {
2025-03-14 17:22:25 +07:00
let _workflow = await new permission().Workflow(request, id, "SYS_EVA_REQ");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_EVA_REQ");
2024-12-04 17:25:34 +07:00
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: [
"authorDoc2",
"subjectDoc2",
"assignedPosition",
"commanderFullnameDoc2",
"commanderPositionDoc2",
"commanderAboveFullnameDoc2",
"commanderAbovePositionDoc2",
2025-01-06 16:19:16 +07:00
"evaluationResult",
2024-12-04 17:25:34 +07:00
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
return new HttpSuccess(evaluation);
} catch (error: any) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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;
commanderPosition: string;
commanderAboveFullname: string;
commanderAbovePosition: 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.");
}
evaluation.author = body.author;
evaluation.subject = body.subject;
evaluation.commanderFullname = body.commanderFullname;
evaluation.commanderPosition = body.commanderPosition;
evaluation.commanderAboveFullname = body.commanderAboveFullname;
evaluation.commanderAbovePosition = body.commanderAbovePosition;
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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;
},
@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.");
}
evaluation.authorDoc2 = body.authorDoc2;
evaluation.subjectDoc2 = body.subjectDoc2;
evaluation.assignedPosition = body.assignedPosition;
evaluation.commanderFullnameDoc2 = body.commanderFullnameDoc2;
evaluation.commanderPositionDoc2 = body.commanderPositionDoc2;
evaluation.commanderAboveFullnameDoc2 = body.commanderAboveFullnameDoc2;
evaluation.commanderAbovePositionDoc2 = body.commanderAbovePositionDoc2;
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) {
2025-03-14 17:22:25 +07:00
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
2024-12-04 17:25:34 +07:00
}
}
/**
* API (USER)
*
* @summary EV1_037 - (USER)
*
* @param {string} id id
*/
@Delete("{id}")
async delete_evaluation(id: string, @Request() request: RequestWithUser) {
2025-03-14 17:22:25 +07:00
try {
// await new permission().PermissionDelete(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({
where: { id },
relations: ["meetings", "directors"],
});
2024-12-04 17:25:34 +07:00
2025-03-14 17:22:25 +07:00
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.evaluationLogsRepository.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);
2024-12-04 17:25:34 +07:00
}
}
/**
* 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) {
2025-03-14 17:22:25 +07:00
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);
2024-12-04 17:25:34 +07:00
}
}
}