start project
This commit is contained in:
commit
0703810fa3
62 changed files with 12665 additions and 0 deletions
761
src/controllers/AssignController.ts
Normal file
761
src/controllers/AssignController.ts
Normal file
|
|
@ -0,0 +1,761 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import { Personal } from "../entities/Personal";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Assign, CreateAssign } from "../entities/Assign";
|
||||
import {
|
||||
AssignDirector,
|
||||
CreateAssignDirector,
|
||||
} from "../entities/AssignDirector";
|
||||
import { AssignJob, CreateAssignJob } from "../entities/AssignJob";
|
||||
import {
|
||||
AssignKnowledge,
|
||||
CreateAssignKnowledge,
|
||||
} from "../entities/AssignKnowledge";
|
||||
import { AssignLaw, CreateAssignLaw } from "../entities/AssignLaw";
|
||||
import { AssignSkill, CreateAssignSkill } from "../entities/AssignSkill";
|
||||
import {
|
||||
AssignCompetency,
|
||||
CreateAssignCompetency,
|
||||
} from "../entities/AssignCompetency";
|
||||
import {
|
||||
AssignCompetencyGroup,
|
||||
CreateAssignCompetencyGroup,
|
||||
} from "../entities/AssignCompetencyGroup";
|
||||
import { AssignOutput, CreateAssignOutput } from "../entities/AssignOutput";
|
||||
import { Law } from "../entities/Law";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/assign")
|
||||
@Tags("ฟอร์มมอบหมายงาน")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class AssignController extends Controller {
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private assignDirectorRepository =
|
||||
AppDataSource.getRepository(AssignDirector);
|
||||
private assignJobRepository = AppDataSource.getRepository(AssignJob);
|
||||
private assignKnowledgeRepository =
|
||||
AppDataSource.getRepository(AssignKnowledge);
|
||||
private assignLawRepository = AppDataSource.getRepository(AssignLaw);
|
||||
private assignSkillRepository = AppDataSource.getRepository(AssignSkill);
|
||||
private assignCompetencyRepository =
|
||||
AppDataSource.getRepository(AssignCompetency);
|
||||
private assignCompetencyGroupRepository = AppDataSource.getRepository(
|
||||
AssignCompetencyGroup
|
||||
);
|
||||
private assignOutputRepository = AppDataSource.getRepository(AssignOutput);
|
||||
private lawsRepository = AppDataSource.getRepository(Law);
|
||||
|
||||
/**
|
||||
* API เพิ่มข้อมูลการมอบหมายงาน
|
||||
*
|
||||
* @summary เพิ่มข้อมูลการมอบหมายงาน
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async AddAssign(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() requestBody: CreateAssign
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: {
|
||||
personal_id: requestBody.personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const roundNo = await this.assignRepository.count({
|
||||
where: {
|
||||
active: 1,
|
||||
personal_id: requestBody.personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
const data: any = {
|
||||
...requestBody,
|
||||
round_no: roundNo + 1,
|
||||
personal_id: requestBody.personal_id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
};
|
||||
const before = null;
|
||||
const assign = await this.assignRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: data });
|
||||
|
||||
const jobs = await requestBody.assign_jobs.map(
|
||||
(x: CreateAssignJob, index: number) => ({
|
||||
...x,
|
||||
id: index + 1,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignJobRepository.save(jobs, { data: request });
|
||||
setLogDataDiff(request, { before, after: jobs });
|
||||
|
||||
const knowledges = await requestBody.assign_knowledges.map(
|
||||
(x: CreateAssignKnowledge, index: number) => ({
|
||||
knowledge_level: x.level,
|
||||
knowledge_id: x.id,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignKnowledgeRepository.save(knowledges, { data: request });
|
||||
setLogDataDiff(request, { before, after: knowledges });
|
||||
|
||||
const laws = await requestBody.assign_law.map(
|
||||
(x: CreateAssignLaw, index: number) => ({
|
||||
ordering: index + 1,
|
||||
law_id: x.id,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignLawRepository.save(laws, { data: request });
|
||||
setLogDataDiff(request, { before, after: laws });
|
||||
|
||||
const skills = await requestBody.assign_skill.map(
|
||||
(x: CreateAssignSkill, index: number) => ({
|
||||
skill_id: index + 1,
|
||||
skill_level: x.level,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignSkillRepository.save(skills, { data: request });
|
||||
setLogDataDiff(request, { before, after: skills });
|
||||
|
||||
const competencise = await requestBody.assign_competency.map(
|
||||
(x: CreateAssignCompetency, index: number) => ({
|
||||
competency_id: x.id,
|
||||
competency_level: x.level,
|
||||
competency_name: x.name,
|
||||
competency_description: x.description,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignCompetencyRepository.save(competencise, { data: request });
|
||||
setLogDataDiff(request, { before, after: competencise });
|
||||
|
||||
const competencyGroups = await requestBody.assign_competency_group.map(
|
||||
(x: CreateAssignCompetencyGroup, index: number) => ({
|
||||
competency_group_id: x.id,
|
||||
competency_group_level: x.level,
|
||||
competency_group_name: x.name,
|
||||
competency_group_description: x.description,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignCompetencyGroupRepository.save(competencyGroups, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before, after: competencyGroups });
|
||||
|
||||
const outputs = await requestBody.assign_outputs.map(
|
||||
(x: CreateAssignOutput, index: number) => ({
|
||||
...x,
|
||||
id: index + 1,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignOutputRepository.save(outputs, { data: request });
|
||||
setLogDataDiff(request, { before, after: outputs });
|
||||
|
||||
const directors = await requestBody.assign_director.map(
|
||||
(x: CreateAssignDirector, index: number) => ({
|
||||
...x,
|
||||
assign_id: assign.id,
|
||||
fullname: x.name,
|
||||
ordering: index + 1,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignDirectorRepository.save(directors, { data: request });
|
||||
setLogDataDiff(request, { before, after: directors });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูลการมอบหมายงาน
|
||||
*
|
||||
* @summary แก้ไขแบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ
|
||||
*
|
||||
*/
|
||||
@Put("")
|
||||
async EditAssign(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser,
|
||||
@Body() requestBody: CreateAssign
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: assign_id },
|
||||
});
|
||||
let before = assign;
|
||||
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: {
|
||||
personal_id: requestBody.personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const data: any = {
|
||||
...requestBody,
|
||||
id: assign_id,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
};
|
||||
|
||||
await this.assignJobRepository.delete({ assign_id });
|
||||
const jobs = await requestBody.assign_jobs.map(
|
||||
(x: CreateAssignJob, index: number) => ({
|
||||
...x,
|
||||
id: index + 1,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignJobRepository.save(jobs);
|
||||
|
||||
await this.assignKnowledgeRepository.delete({ assign_id });
|
||||
const knowledges = await requestBody.assign_knowledges.map(
|
||||
(x: CreateAssignKnowledge, index: number) => ({
|
||||
knowledge_level: x.level,
|
||||
knowledge_id: x.id,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignKnowledgeRepository.save(knowledges);
|
||||
|
||||
await this.assignLawRepository.delete({ assign_id });
|
||||
const laws = await requestBody.assign_law.map(
|
||||
(x: CreateAssignLaw, index: number) => ({
|
||||
ordering: index + 1,
|
||||
law_id: x.id,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignLawRepository.save(laws);
|
||||
|
||||
await this.assignSkillRepository.delete({ assign_id });
|
||||
const skills = await requestBody.assign_skill.map(
|
||||
(x: CreateAssignSkill, index: number) => ({
|
||||
skill_id: index + 1,
|
||||
skill_level: x.level,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignSkillRepository.save(skills);
|
||||
|
||||
await this.assignCompetencyRepository.delete({ assign_id });
|
||||
const competencise = await requestBody.assign_competency.map(
|
||||
(x: CreateAssignCompetency, index: number) => ({
|
||||
competency_id: x.id,
|
||||
competency_level: x.level,
|
||||
competency_name: x.name,
|
||||
competency_description: x.description,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignCompetencyRepository.save(competencise);
|
||||
|
||||
await this.assignCompetencyGroupRepository.delete({ assign_id });
|
||||
const competencyGroups = await requestBody.assign_competency_group.map(
|
||||
(x: CreateAssignCompetencyGroup, index: number) => ({
|
||||
competency_group_id: x.id,
|
||||
competency_group_level: x.level,
|
||||
competency_group_name: x.name,
|
||||
competency_group_description: x.description,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignCompetencyGroupRepository.save(competencyGroups);
|
||||
|
||||
await this.assignOutputRepository.delete({ assign_id });
|
||||
const outputs = await requestBody.assign_outputs.map(
|
||||
(x: CreateAssignOutput, index: number) => ({
|
||||
...x,
|
||||
id: index + 1,
|
||||
assign_id: assign.id,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignOutputRepository.save(outputs);
|
||||
|
||||
await this.assignDirectorRepository.delete({ assign_id });
|
||||
const directors = await requestBody.assign_director.map(
|
||||
(x: CreateAssignDirector, index: number) => ({
|
||||
...x,
|
||||
assign_id: assign.id,
|
||||
fullname: x.name,
|
||||
ordering: index + 1,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
})
|
||||
);
|
||||
await this.assignDirectorRepository.save(directors);
|
||||
|
||||
await this.assignRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: data });
|
||||
|
||||
// #noted cronjob
|
||||
// แจ้งผู้ดูแลและผู้บังคับบัญชาเข้ามาบันทึกผลทุก 2 เดือน
|
||||
const dateSaveForm = await findEndDate(2, requestBody.date_start);
|
||||
requestBody.assign_director
|
||||
.filter((x) => x.role == "mentor" || x.role == "commander")
|
||||
.map(async (director) => {
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: `ถึงกำหนดบันทึกผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||
body: `ถึงกำหนดบันทึกผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||
receiverUserId: director.personal_id,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
receiveDate: dateSaveForm,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
});
|
||||
|
||||
// แจ้งผู้บังคับบัญชา และคณะกรรมการเข้ามาประเมินทุก 3 เดือน
|
||||
const dateEvaluate = await findEndDate(3, requestBody.date_start);
|
||||
requestBody.assign_director
|
||||
.filter((x) => x.role == "commander" || x.role == "chairman")
|
||||
.map(async (director) => {
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ 1 ${requestBody.fullname}`,
|
||||
receiverUserId: director.personal_id,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
receiveDate: dateEvaluate,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
});
|
||||
|
||||
// แจ้งประธาน 6 เดือน
|
||||
const dateResult = await findEndDate(6, requestBody.date_start);
|
||||
requestBody.assign_director
|
||||
.filter((x) => x.role == "chairman")
|
||||
.map(async (director) => {
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: `ถึงกำหนดรายงานการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ ${requestBody.fullname}`,
|
||||
body: `ถึงกำหนดรายงานการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ ${requestBody.fullname}`,
|
||||
receiverUserId: director.personal_id,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
// isSendNotification: true
|
||||
receiveDate: dateResult,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
});
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการข้อมูลการมอบหมายงาน
|
||||
*
|
||||
* @summary รายการการมอบหมายงาน
|
||||
*
|
||||
*/
|
||||
@Get("assign-list")
|
||||
async ListPersonal(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() personal_id: string
|
||||
) {
|
||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
const lists = await this.assignRepository.find({
|
||||
select: ["id", "round_no", "date_start", "date_finish"],
|
||||
where: { personal_id },
|
||||
order: { round_no: "ASC" },
|
||||
});
|
||||
|
||||
let result: any = [];
|
||||
|
||||
await Promise.all(
|
||||
lists.map(async (item) => {
|
||||
const director = await this.assignDirectorRepository.find({
|
||||
where: { assign_id: item.id },
|
||||
});
|
||||
|
||||
let mentors = "";
|
||||
const mentorList = await director.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors += e.fullname;
|
||||
if (index < mentorList.length - 1) {
|
||||
mentors += ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (director.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commander = commanderData ? commanderData.fullname : null;
|
||||
|
||||
const chairmanData = await (director.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||
|
||||
await result.push({
|
||||
...item,
|
||||
mentors: mentors,
|
||||
commander: commander,
|
||||
chairman: chairman,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ดึงข้อมูลแบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ
|
||||
*
|
||||
* @summary ดึงข้อมูลแบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetAssign(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
select: [
|
||||
"id",
|
||||
"personal_id",
|
||||
"round_no",
|
||||
"date_start",
|
||||
"date_finish",
|
||||
"other4_desc",
|
||||
"other5_no1_desc",
|
||||
"experimenter_dated",
|
||||
"active",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const profileData = await this.personalRepository.findOne({
|
||||
select: [
|
||||
"personal_id",
|
||||
"prefixName",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"positionName",
|
||||
"positionLevelName",
|
||||
"positionLineName",
|
||||
"orgRootName",
|
||||
"organization",
|
||||
],
|
||||
where: {
|
||||
personal_id: assign.personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!profileData) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const profile = {
|
||||
...profileData,
|
||||
name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`,
|
||||
Position: profileData.positionName,
|
||||
Department: "-",
|
||||
OrganizationOrganization: profileData.orgRootName,
|
||||
Oc: profileData.organization,
|
||||
};
|
||||
|
||||
const jobs = await this.assignJobRepository.find({
|
||||
select: ["id", "activity_desc", "goal_desc"],
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
const knowledgeData = await this.assignKnowledgeRepository.find({
|
||||
relations: ["knowledge"],
|
||||
where: { assign_id },
|
||||
});
|
||||
const knowledges = await knowledgeData.map((x) => ({
|
||||
id: x.knowledge_id,
|
||||
level: x.knowledge_level,
|
||||
title: x.knowledge.title,
|
||||
description:
|
||||
x.knowledge_level == 1
|
||||
? x.knowledge.level1
|
||||
: x.knowledge_level == 2
|
||||
? x.knowledge.level2
|
||||
: x.knowledge_level == 3
|
||||
? x.knowledge.level3
|
||||
: x.knowledge_level == 4
|
||||
? x.knowledge.level4
|
||||
: x.knowledge_level == 5
|
||||
? x.knowledge.level5
|
||||
: "",
|
||||
}));
|
||||
|
||||
const lawData = await this.lawsRepository.find({
|
||||
where: { active: 1 },
|
||||
});
|
||||
|
||||
const laws = await lawData.map((x) => ({
|
||||
id: x.id,
|
||||
selected: x.assignLaw ? 1 : 0,
|
||||
description: x.description,
|
||||
status_select: x.status_select,
|
||||
}));
|
||||
|
||||
const skillsData = await this.assignSkillRepository.find({
|
||||
relations: ["skill"],
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
const skills = await skillsData.map((x) => ({
|
||||
id: x.skill_id,
|
||||
level: x.skill_level,
|
||||
title: x.skill.title,
|
||||
description:
|
||||
x.skill_level == 1
|
||||
? x.skill.level1
|
||||
: x.skill_level == 2
|
||||
? x.skill.level2
|
||||
: x.skill_level == 3
|
||||
? x.skill.level3
|
||||
: x.skill_level == 4
|
||||
? x.skill.level4
|
||||
: x.skill_level == 5
|
||||
? x.skill.level5
|
||||
: "",
|
||||
}));
|
||||
|
||||
const competencyData = await this.assignCompetencyRepository.find({
|
||||
select: [
|
||||
"competency_id",
|
||||
"competency_level",
|
||||
"competency_name",
|
||||
"competency_description",
|
||||
],
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
const competencys = await competencyData.map((x) => ({
|
||||
id: x.competency_id,
|
||||
level: x.competency_level,
|
||||
name: x.competency_name,
|
||||
description: x.competency_description,
|
||||
}));
|
||||
|
||||
const competencyGroupData = await this.assignCompetencyGroupRepository.find(
|
||||
{
|
||||
select: [
|
||||
"competency_group_id",
|
||||
"competency_group_level",
|
||||
"competency_group_name",
|
||||
"competency_group_description",
|
||||
],
|
||||
where: { assign_id },
|
||||
}
|
||||
);
|
||||
const competency_groups = await competencyGroupData.map((x) => ({
|
||||
id: x.competency_group_id,
|
||||
level: x.competency_group_level,
|
||||
name: x.competency_group_name,
|
||||
description: x.competency_group_description,
|
||||
}));
|
||||
|
||||
const outputs = await this.assignOutputRepository.find({
|
||||
select: ["id", "output_desc", "indicator_desc"],
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
const director = await this.assignDirectorRepository.find({
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
let mentors = [];
|
||||
const mentorList = await director.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors.push({
|
||||
...e,
|
||||
name: e.fullname,
|
||||
label:
|
||||
e.fullname +
|
||||
" " +
|
||||
(e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
|
||||
Position: e.position, // report
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (director.find((x) => x.role == "commander") ??
|
||||
null);
|
||||
const commander = await (commanderData
|
||||
? {
|
||||
...commanderData,
|
||||
name: commanderData.fullname,
|
||||
label:
|
||||
commanderData.fullname +
|
||||
" " +
|
||||
(commanderData.position
|
||||
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
|
||||
: ""),
|
||||
Position: commanderData.position, // report
|
||||
}
|
||||
: null);
|
||||
|
||||
const chairmanData = await (director.find((x) => x.role == "chairman") ??
|
||||
null);
|
||||
const chairman = await (chairmanData
|
||||
? {
|
||||
...chairmanData,
|
||||
name: chairmanData.fullname,
|
||||
label:
|
||||
chairmanData.fullname +
|
||||
" " +
|
||||
(chairmanData.position
|
||||
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
|
||||
: ""),
|
||||
Position: chairmanData.position, // report
|
||||
}
|
||||
: null);
|
||||
|
||||
return new HttpSuccess({
|
||||
assign,
|
||||
profile,
|
||||
jobs,
|
||||
knowledges,
|
||||
laws,
|
||||
skills,
|
||||
competencys,
|
||||
competency_groups,
|
||||
outputs,
|
||||
mentors,
|
||||
commander,
|
||||
chairman,
|
||||
});
|
||||
}
|
||||
}
|
||||
47
src/controllers/CalculateController.ts
Normal file
47
src/controllers/CalculateController.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { findEndDate } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/calculate")
|
||||
@Tags("ฟอร์มมอบหมายงาน")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class CalculateController extends Controller {
|
||||
/**
|
||||
* API คำนวนวันสิ้นสุดตามวันที่เริ่มและระยะเวลาเดือนตามที่ส่งค่ามา
|
||||
*
|
||||
* @summary คำนวนวันสิ้นสุดตามวันที่เริ่มและระยะเวลาเดือนตามที่ส่งค่ามา
|
||||
*
|
||||
*/
|
||||
@Post("assign-finish")
|
||||
async AssignFinish(
|
||||
@Body()
|
||||
requestBody: {
|
||||
month: number;
|
||||
start_date: Date;
|
||||
},
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const { month, start_date } = requestBody;
|
||||
const finish_date = findEndDate(month, start_date);
|
||||
|
||||
return new HttpSuccess({ finish_date });
|
||||
}
|
||||
}
|
||||
302
src/controllers/DataOptionsController.ts
Normal file
302
src/controllers/DataOptionsController.ts
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Knowledge, TypeKnowledge } from "../entities/Knowledge";
|
||||
import { Skill, TypeSkill } from "../entities/Skill";
|
||||
import { MapKnowledgeSkill } from "../entities/MapKnowledgeSkill";
|
||||
import { Personal } from "../entities/Personal";
|
||||
import { Law } from "../entities/Law";
|
||||
import { Assign } from "../entities/Assign";
|
||||
|
||||
@Route("api/v1/data-options")
|
||||
@Tags("Data Options")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class DataOptionController extends Controller {
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private knowledgeRepository = AppDataSource.getRepository(Knowledge);
|
||||
private mapKnowledgeSkillRepository =
|
||||
AppDataSource.getRepository(MapKnowledgeSkill);
|
||||
private skillRepository = AppDataSource.getRepository(Skill);
|
||||
private lawRepository = AppDataSource.getRepository(Law);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
|
||||
/**
|
||||
* API list รายการความรู้
|
||||
*
|
||||
* @summary options ความรู้
|
||||
*
|
||||
*/
|
||||
@Get("knowledge")
|
||||
async GetKnowledge(
|
||||
@Query() personal_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: { personal_id },
|
||||
});
|
||||
|
||||
console.log(person);
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const result = await this.mapKnowledgeSkillRepository.findOne({
|
||||
where: {
|
||||
positionName: person.positionName,
|
||||
positionLevelName: person.positionLevelName,
|
||||
active: 1,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const knowledges = await this.knowledgeRepository.find({
|
||||
where: { type: TypeKnowledge.PERFORMANCE, active: 1 },
|
||||
});
|
||||
|
||||
const knowledge = knowledges.map((knowledge) => ({
|
||||
id: knowledge.id,
|
||||
title: knowledge.title,
|
||||
description:
|
||||
result.knowlage_performance_level == 1
|
||||
? knowledge.level1
|
||||
: result.knowlage_performance_level == 2
|
||||
? knowledge.level2
|
||||
: result.knowlage_performance_level == 3
|
||||
? knowledge.level3
|
||||
: result.knowlage_performance_level == 4
|
||||
? knowledge.level4
|
||||
: knowledge.level5,
|
||||
level: result.knowlage_performance_level,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(knowledge);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลทักษะ
|
||||
*
|
||||
* @summary options ทักษะ
|
||||
*
|
||||
*/
|
||||
@Get("skill")
|
||||
async GetSkill(
|
||||
@Query() personal_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: { personal_id },
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const result = await this.mapKnowledgeSkillRepository.findOne({
|
||||
select: [
|
||||
"skill_computer_level",
|
||||
"skill_english_level",
|
||||
"skill_information_level",
|
||||
"skill_resourse_level",
|
||||
],
|
||||
where: {
|
||||
positionName: person.positionName,
|
||||
positionLevelName: person.positionLevelName,
|
||||
active: 1,
|
||||
},
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const skills = await this.skillRepository.find({
|
||||
where: { type: TypeSkill.COMPUTER, active: 1 },
|
||||
});
|
||||
const skill = await skills.map((v) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
level_description:
|
||||
result.skill_english_level == 1
|
||||
? v.level1
|
||||
: result.skill_english_level == 2
|
||||
? v.level2
|
||||
: result.skill_english_level == 3
|
||||
? v.level3
|
||||
: result.skill_english_level == 4
|
||||
? v.level4
|
||||
: v.level5,
|
||||
level: result.skill_english_level,
|
||||
}));
|
||||
|
||||
const englishs = await this.skillRepository.find({
|
||||
where: { type: TypeSkill.ENG, active: 1 },
|
||||
});
|
||||
const english = await englishs.map((v) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
level_description:
|
||||
result.skill_english_level == 1
|
||||
? v.level1
|
||||
: result.skill_english_level == 2
|
||||
? v.level2
|
||||
: result.skill_english_level == 3
|
||||
? v.level3
|
||||
: result.skill_english_level == 4
|
||||
? v.level4
|
||||
: v.level5,
|
||||
level: result.skill_english_level,
|
||||
}));
|
||||
|
||||
const informations = await this.skillRepository.find({
|
||||
where: { type: TypeSkill.INFORMATION, active: 1 },
|
||||
});
|
||||
const information = await informations.map((v) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
level_description:
|
||||
result.skill_information_level == 1
|
||||
? v.level1
|
||||
: result.skill_information_level == 2
|
||||
? v.level2
|
||||
: result.skill_information_level == 3
|
||||
? v.level3
|
||||
: result.skill_information_level == 4
|
||||
? v.level4
|
||||
: v.level5,
|
||||
level: result.skill_information_level,
|
||||
}));
|
||||
|
||||
const resourses = await this.skillRepository.find({
|
||||
where: { type: TypeSkill.RESOURSE, active: 1 },
|
||||
});
|
||||
const resourse = await resourses.map((v) => ({
|
||||
id: v.id,
|
||||
title: v.title,
|
||||
level_description:
|
||||
result.skill_resourse_level == 1
|
||||
? v.level1
|
||||
: result.skill_resourse_level == 2
|
||||
? v.level2
|
||||
: result.skill_resourse_level == 3
|
||||
? v.level3
|
||||
: result.skill_resourse_level == 4
|
||||
? v.level4
|
||||
: v.level5,
|
||||
level: result.skill_resourse_level,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({
|
||||
computer: skill,
|
||||
english: english,
|
||||
information: information,
|
||||
resourse: resourse,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API list รายการกฎหมาย
|
||||
*
|
||||
* @summary options กฎหมาย
|
||||
*
|
||||
*/
|
||||
@Get("law")
|
||||
async GetLaw(
|
||||
@Query() personal_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const results = await this.lawRepository.find({
|
||||
select: ["id", "parent_id", "description", "status_select"],
|
||||
where: {
|
||||
active: 1,
|
||||
},
|
||||
});
|
||||
|
||||
if (!results) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const result = await results.map((v) => ({
|
||||
...v,
|
||||
checked: 0,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
||||
*
|
||||
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
||||
*
|
||||
*/
|
||||
@Get("new-assign")
|
||||
async NewAssign(
|
||||
@Query() personal_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const person = await this.personalRepository.findOne({
|
||||
select: [
|
||||
"personal_id",
|
||||
"prefixName",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"posNo",
|
||||
"positionName",
|
||||
"positionLevelName",
|
||||
"positionLineName",
|
||||
"isProbation",
|
||||
"orgRootName",
|
||||
"organization",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
],
|
||||
where: { personal_id },
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const assign = await this.assignRepository.count({
|
||||
where: {
|
||||
personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
const responsePerson = {
|
||||
id: person.personal_id,
|
||||
...person,
|
||||
};
|
||||
|
||||
const data = await {
|
||||
person: responsePerson,
|
||||
assign_no: assign + 1,
|
||||
assign_month: 6,
|
||||
};
|
||||
|
||||
return new HttpSuccess({ data: data });
|
||||
}
|
||||
}
|
||||
444
src/controllers/EvaluateChairmanController.ts
Normal file
444
src/controllers/EvaluateChairmanController.ts
Normal file
|
|
@ -0,0 +1,444 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Query,
|
||||
Put,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { AssignDirector } from "../entities/AssignDirector";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import { Personal } from "../entities/Personal";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import {
|
||||
CreateEvaluateChairman,
|
||||
EvaluateChairman,
|
||||
} from "../entities/EvaluateChairman";
|
||||
|
||||
@Route("api/v1/evaluate-chairman")
|
||||
@Tags("แบบประเมินผล (คณะกรรมการ)")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class EvaluateChairmanController extends Controller {
|
||||
private assignDirectorRepository =
|
||||
AppDataSource.getRepository(AssignDirector);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private evaluateChairmanRepository =
|
||||
AppDataSource.getRepository(EvaluateChairman);
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
|
||||
/**
|
||||
* API ข้อมูลตอนกดสร้างแบบประเมินผล (คณะกรรมการ)
|
||||
*
|
||||
* @summary ข้อมูลตอนกดสร้างแบบประเมินผล (คณะกรรมการ)
|
||||
*
|
||||
*/
|
||||
@Get("create")
|
||||
async CreateEvaluate(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "chairman",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const profile = await (assign.profile
|
||||
? {
|
||||
...assign.profile,
|
||||
id: assign.profile.personal_id,
|
||||
name:
|
||||
assign.profile.prefixName +
|
||||
assign.profile.firstName +
|
||||
" " +
|
||||
assign.profile.lastName,
|
||||
Oc: assign.profile.organization,
|
||||
}
|
||||
: null);
|
||||
|
||||
const evaluate_amount = await this.evaluateChairmanRepository.count({
|
||||
where: {
|
||||
assign_id,
|
||||
director_id,
|
||||
},
|
||||
});
|
||||
const evaluate_no = await (evaluate_amount + 1);
|
||||
const start_date =
|
||||
evaluate_amount == 0
|
||||
? assign.date_start
|
||||
: findEndDate(evaluate_amount * 3, assign.date_start);
|
||||
|
||||
const directorData = await this.assignDirectorRepository.find({
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
if (!directorData) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
}
|
||||
|
||||
let mentors = "";
|
||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors += e.fullname;
|
||||
if (index < mentorList.length - 1) {
|
||||
mentors += ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (directorData.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commander = commanderData ? commanderData.fullname : null;
|
||||
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||
|
||||
return new HttpSuccess({
|
||||
person: profile ? profile : null,
|
||||
assign,
|
||||
evaluate_no: evaluate_no,
|
||||
start_date: start_date,
|
||||
end_date: findEndDate(3, start_date),
|
||||
commander,
|
||||
mentors,
|
||||
chairman,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลแบบประเมินผล (คณะกรรมการ)
|
||||
*
|
||||
* @summary ข้อมูลแบบประเมินผล (คณะกรรมการ)
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetEvaluate(@Query() assign_id: string, @Query() evaluate_no?: string) {
|
||||
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "chairman",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
const director_id = director.personal_id;
|
||||
let evaluate: any = null;
|
||||
if (evaluate_no) {
|
||||
evaluate = await this.evaluateChairmanRepository.findOne({
|
||||
where: {
|
||||
director_id,
|
||||
assign_id,
|
||||
no: evaluate_no,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
evaluate = await this.evaluateChairmanRepository.findOne({
|
||||
where: {
|
||||
director_id,
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
|
||||
}
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const experimenteeData = await this.personalRepository.find({
|
||||
select: [
|
||||
"personal_id",
|
||||
"prefixName",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"positionName",
|
||||
"positionLevelName",
|
||||
"organization",
|
||||
],
|
||||
where: { personal_id: assign.personal_id },
|
||||
});
|
||||
|
||||
const experimentee = await experimenteeData.map((element) => ({
|
||||
...element,
|
||||
name: element.prefixName + element.firstName + " " + element.lastName,
|
||||
Oc: element.organization,
|
||||
}));
|
||||
|
||||
const directorData = await this.assignDirectorRepository.find({
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
if (!directorData) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
}
|
||||
|
||||
let mentors = "";
|
||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors += e.fullname;
|
||||
if (index < mentorList.length - 1) {
|
||||
mentors += ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (directorData.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commander = commanderData ? commanderData.fullname : null;
|
||||
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||
|
||||
return new HttpSuccess({
|
||||
experimentee: experimentee,
|
||||
mentors: mentors,
|
||||
commander: commander,
|
||||
chairman: chairman,
|
||||
assign,
|
||||
evaluate,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostData(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: CreateEvaluateChairman,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "chairman",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const postData: any = await {
|
||||
assign_id,
|
||||
...requestBody,
|
||||
director_id,
|
||||
no: requestBody.evaluate_no,
|
||||
date_start: requestBody.start_date,
|
||||
personal_id: assign.personal_id,
|
||||
|
||||
achievement_other_desc: requestBody.achievement_other
|
||||
? requestBody.achievement_other.text
|
||||
: "",
|
||||
achievement_other_level: requestBody.achievement_other
|
||||
? Number(requestBody.achievement_other.level)
|
||||
: 0,
|
||||
behavior_other_desc: requestBody.behavior_orther.text,
|
||||
behavior_other_level:
|
||||
requestBody.behavior_orther.text != ""
|
||||
? Number(requestBody.behavior_orther.level)
|
||||
: 0,
|
||||
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
};
|
||||
|
||||
await this.evaluateChairmanRepository.save(postData, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before: null, after: postData });
|
||||
|
||||
if (Number(requestBody.evaluate_no) < 2) {
|
||||
// #noted cronjob
|
||||
// แจ้งประธานเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
|
||||
var dateSend = await findEndDate(3, requestBody.start_date);
|
||||
const nextNo = await (Number(requestBody.evaluate_no) + 1);
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับคณะกรรมการ) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||
receiverUserId: director_id,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
receiveDate: dateSend,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Put("")
|
||||
async UpdateData(
|
||||
@Query() assign_id: string,
|
||||
@Query() evaluate_id: string,
|
||||
@Body() requestBody: CreateEvaluateChairman,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
let evaluate = await this.evaluateChairmanRepository.findOne({
|
||||
where: { id: evaluate_id },
|
||||
});
|
||||
|
||||
const before = evaluate;
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
|
||||
}
|
||||
|
||||
evaluate.chairman_dated = requestBody.chairman_dated;
|
||||
evaluate.director1_dated = requestBody.director1_dated;
|
||||
evaluate.director2_dated = requestBody.director2_dated;
|
||||
evaluate.knowledge_level = requestBody.knowledge_level;
|
||||
evaluate.apply_level = requestBody.apply_level;
|
||||
evaluate.success_level = requestBody.success_level;
|
||||
evaluate.achievement_other_desc = requestBody.achievement_other
|
||||
? requestBody.achievement_other.text
|
||||
: "";
|
||||
evaluate.achievement_other_level =
|
||||
requestBody.achievement_other.text != ""
|
||||
? Number(requestBody.achievement_other.level)
|
||||
: 0;
|
||||
|
||||
evaluate.conduct1_level = requestBody.conduct1_level;
|
||||
evaluate.conduct2_level = requestBody.conduct2_level;
|
||||
evaluate.conduct3_level = requestBody.conduct3_level;
|
||||
evaluate.conduct4_level = requestBody.conduct4_level;
|
||||
evaluate.moral1_level = requestBody.moral1_level;
|
||||
evaluate.moral2_level = requestBody.moral2_level;
|
||||
evaluate.moral3_level = requestBody.moral3_level;
|
||||
evaluate.discipline1_level = requestBody.discipline1_level;
|
||||
evaluate.discipline2_level = requestBody.discipline2_level;
|
||||
evaluate.discipline3_level = requestBody.discipline3_level;
|
||||
evaluate.discipline4_level = requestBody.discipline4_level;
|
||||
evaluate.discipline5_level = requestBody.discipline5_level;
|
||||
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
|
||||
evaluate.behavior_other_level =
|
||||
requestBody.behavior_orther.text != ""
|
||||
? Number(requestBody.behavior_orther.level)
|
||||
: 0;
|
||||
evaluate.develop_orientation_score = requestBody.develop_orientation_score;
|
||||
evaluate.develop_self_learning_score =
|
||||
requestBody.develop_self_learning_score;
|
||||
evaluate.develop_training_seminar_score =
|
||||
requestBody.develop_training_seminar_score;
|
||||
evaluate.develop_other_training_score =
|
||||
requestBody.develop_other_training_score;
|
||||
evaluate.develop_orientation_percent =
|
||||
requestBody.develop_orientation_percent;
|
||||
evaluate.develop_self_learning_percent =
|
||||
requestBody.develop_self_learning_percent;
|
||||
evaluate.develop_training_seminar_percent =
|
||||
requestBody.develop_training_seminar_percent;
|
||||
evaluate.develop_other_training_percent =
|
||||
requestBody.develop_other_training_percent;
|
||||
evaluate.develop_result = requestBody.develop_result;
|
||||
evaluate.achievement_score = requestBody.achievement_score;
|
||||
evaluate.achievement_score_total = requestBody.achievement_score_total;
|
||||
evaluate.achievement_percent = requestBody.achievement_percent;
|
||||
evaluate.achievement_result = requestBody.achievement_result;
|
||||
evaluate.behavior_score = requestBody.behavior_score;
|
||||
evaluate.behavior_score_total = requestBody.behavior_score_total;
|
||||
evaluate.behavior_percent = requestBody.behavior_percent;
|
||||
evaluate.behavior_result = requestBody.behavior_result;
|
||||
evaluate.sum_score = requestBody.sum_score;
|
||||
evaluate.sum_percent = requestBody.sum_percent;
|
||||
evaluate.evaluate_result = requestBody.evaluate_result;
|
||||
|
||||
evaluate.updateUserId = request.user.sub;
|
||||
evaluate.updateFullName = request.user.name;
|
||||
|
||||
await this.evaluateChairmanRepository.save(evaluate, { data: request });
|
||||
setLogDataDiff(request, { before, after: evaluate });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
414
src/controllers/EvaluateController.ts
Normal file
414
src/controllers/EvaluateController.ts
Normal file
|
|
@ -0,0 +1,414 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Query,
|
||||
Put,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { AssignDirector } from "../entities/AssignDirector";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import {
|
||||
CreateEvaluateCommander,
|
||||
EvaluateCommander,
|
||||
} from "../entities/EvaluateCommander";
|
||||
import { Personal } from "../entities/Personal";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
|
||||
@Route("api/v1/evaluate")
|
||||
@Tags("แบบประเมินผล (ผู้บังคับบัญชา)")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class EvaluateController extends Controller {
|
||||
private assignDirectorRepository =
|
||||
AppDataSource.getRepository(AssignDirector);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private evaluateCommanderRepository =
|
||||
AppDataSource.getRepository(EvaluateCommander);
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
|
||||
/**
|
||||
* API ข้อมูลตอนกดสร้างแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary ข้อมูลตอนกดสร้างแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Get("create")
|
||||
async CreateEvaluate(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "commander",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const profile = await (assign.profile
|
||||
? {
|
||||
...assign.profile,
|
||||
id: assign.profile.personal_id,
|
||||
name:
|
||||
assign.profile.prefixName +
|
||||
assign.profile.firstName +
|
||||
" " +
|
||||
assign.profile.lastName,
|
||||
Oc: assign.profile.organization,
|
||||
}
|
||||
: null);
|
||||
|
||||
const evaluate_amount = await this.evaluateCommanderRepository.count({
|
||||
where: {
|
||||
assign_id,
|
||||
director_id,
|
||||
},
|
||||
});
|
||||
const evaluate_no = await (evaluate_amount + 1);
|
||||
const start_date =
|
||||
evaluate_amount == 0
|
||||
? assign.date_start
|
||||
: findEndDate(evaluate_amount * 3, assign.date_start);
|
||||
|
||||
const commanderData = await this.assignDirectorRepository.find({
|
||||
select: [
|
||||
"personal_id",
|
||||
"dated",
|
||||
"fullname",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
],
|
||||
where: { personal_id: director_id },
|
||||
});
|
||||
|
||||
const commander = await commanderData.map((element) => ({
|
||||
...element,
|
||||
name: element.fullname,
|
||||
label: `${element.fullname} (${element.position}, ${element.posType}: ${element.posLevel})`,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({
|
||||
person: profile,
|
||||
assign,
|
||||
evaluate_no: evaluate_no,
|
||||
start_date: start_date,
|
||||
end_date: findEndDate(3, start_date),
|
||||
director: commander,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetEvaluate(@Query() assign_id: string, @Query() evaluate_no?: string) {
|
||||
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "commander",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
const director_id = director.personal_id;
|
||||
let evaluate: any = null;
|
||||
if (evaluate_no) {
|
||||
evaluate = await this.evaluateCommanderRepository.findOne({
|
||||
where: {
|
||||
director_id,
|
||||
assign_id,
|
||||
no: evaluate_no,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
evaluate = await this.evaluateCommanderRepository.findOne({
|
||||
where: {
|
||||
director_id,
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
|
||||
}
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
// const profile = await (assign.profile
|
||||
// ? {
|
||||
// ...assign.profile,
|
||||
// id: assign.profile.personal_id,
|
||||
// name:
|
||||
// assign.profile.prefixName +
|
||||
// assign.profile.firstName +
|
||||
// " " +
|
||||
// assign.profile.lastName,
|
||||
// Oc: assign.profile.organization,
|
||||
// }
|
||||
// : null);
|
||||
|
||||
// const evaluate_amount = await this.evaluateCommanderRepository.count({
|
||||
// where: {
|
||||
// assign_id,
|
||||
// director_id,
|
||||
// },
|
||||
// });
|
||||
// const evaluate_no = await (evaluate_amount + 1);
|
||||
// const start_date =
|
||||
// evaluate_amount == 0
|
||||
// ? assign.date_start
|
||||
// : findEndDate(evaluate_amount * 3, assign.date_start);
|
||||
|
||||
const directorData = await this.assignDirectorRepository.find({
|
||||
select: [
|
||||
"personal_id",
|
||||
"dated",
|
||||
"fullname",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
],
|
||||
where: { personal_id: director_id },
|
||||
});
|
||||
|
||||
const directors = await directorData.map((element) => ({
|
||||
...element,
|
||||
name: element.fullname,
|
||||
label: `${element.fullname} (${element.position}, ${element.posType}: ${element.posLevel})`,
|
||||
}));
|
||||
|
||||
const experimenteeData = await this.personalRepository.find({
|
||||
select: [
|
||||
"personal_id",
|
||||
"prefixName",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"positionName",
|
||||
"positionLevelName",
|
||||
"organization",
|
||||
],
|
||||
where: { personal_id: assign.personal_id },
|
||||
});
|
||||
|
||||
const experimentee = await experimenteeData.map((element) => ({
|
||||
...element,
|
||||
name: element.prefixName + element.firstName + " " + element.lastName,
|
||||
Oc: element.organization,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({
|
||||
experimentee: experimentee,
|
||||
director: directors ? directors : null,
|
||||
assign,
|
||||
evaluate,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostData(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: CreateEvaluateCommander,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "commander",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const postData: any = await {
|
||||
assign_id,
|
||||
...requestBody,
|
||||
director_id,
|
||||
no: requestBody.evaluate_no,
|
||||
date_start: requestBody.start_date,
|
||||
personal_id: assign.personal_id,
|
||||
|
||||
achievement_other_desc: requestBody.achievement_other
|
||||
? requestBody.achievement_other.text
|
||||
: "",
|
||||
achievement_other_level: requestBody.achievement_other
|
||||
? Number(requestBody.achievement_other.level)
|
||||
: 0,
|
||||
behavior_other_desc: requestBody.behavior_orther.text,
|
||||
behavior_other_level:
|
||||
requestBody.behavior_orther.text != ""
|
||||
? Number(requestBody.behavior_orther.level)
|
||||
: 0,
|
||||
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
};
|
||||
|
||||
await this.evaluateCommanderRepository.save(postData, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before: null, after: postData });
|
||||
|
||||
if (Number(requestBody.evaluate_no) < 2) {
|
||||
// #noted cronjob
|
||||
// แจ้งผู้บังคับบัญชาเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
|
||||
var dateSend = await findEndDate(3, requestBody.start_date);
|
||||
const nextNo = await (Number(requestBody.evaluate_no) + 1);
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับผู้บังคับบัญชา) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||
receiverUserId: director_id,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
receiveDate: dateSend,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
* @summary แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||
*
|
||||
*/
|
||||
@Put("")
|
||||
async UpdateData(
|
||||
@Query() assign_id: string,
|
||||
@Query() evaluate_id: string,
|
||||
@Body() requestBody: CreateEvaluateCommander,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
let evaluate = await this.evaluateCommanderRepository.findOne({
|
||||
where: { id: evaluate_id },
|
||||
});
|
||||
|
||||
const before = evaluate;
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
|
||||
}
|
||||
|
||||
evaluate.commander_dated = requestBody.commander_dated;
|
||||
evaluate.knowledge_level = requestBody.knowledge_level;
|
||||
evaluate.skill_level = requestBody.skill_level;
|
||||
evaluate.competency_level = requestBody.competency_level;
|
||||
evaluate.learn_level = requestBody.learn_level;
|
||||
evaluate.apply_level = requestBody.apply_level;
|
||||
evaluate.success_level = requestBody.success_level;
|
||||
evaluate.achievement_other_desc = requestBody.achievement_other
|
||||
? requestBody.achievement_other.text
|
||||
: "";
|
||||
evaluate.achievement_other_level =
|
||||
requestBody.achievement_other.text != ""
|
||||
? Number(requestBody.achievement_other.level)
|
||||
: 0;
|
||||
|
||||
evaluate.conduct1_level = requestBody.conduct1_level;
|
||||
evaluate.conduct2_level = requestBody.conduct2_level;
|
||||
evaluate.conduct3_level = requestBody.conduct3_level;
|
||||
evaluate.conduct4_level = requestBody.conduct4_level;
|
||||
evaluate.moral1_level = requestBody.moral1_level;
|
||||
evaluate.moral2_level = requestBody.moral2_level;
|
||||
evaluate.moral3_level = requestBody.moral3_level;
|
||||
evaluate.discipline1_level = requestBody.discipline1_level;
|
||||
evaluate.discipline2_level = requestBody.discipline2_level;
|
||||
evaluate.discipline3_level = requestBody.discipline3_level;
|
||||
evaluate.discipline4_level = requestBody.discipline4_level;
|
||||
evaluate.discipline5_level = requestBody.discipline5_level;
|
||||
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
|
||||
evaluate.behavior_other_level =
|
||||
requestBody.behavior_orther.text != ""
|
||||
? Number(requestBody.behavior_orther.level)
|
||||
: 0;
|
||||
evaluate.behavior_strength_desc = requestBody.behavior_strength_desc;
|
||||
evaluate.behavior_improve_desc = requestBody.behavior_improve_desc;
|
||||
evaluate.orientation = requestBody.orientation;
|
||||
evaluate.self_learning = requestBody.self_learning;
|
||||
evaluate.training_seminar = requestBody.training_seminar;
|
||||
evaluate.other_training = requestBody.other_training;
|
||||
evaluate.updateUserId = request.user.sub;
|
||||
evaluate.updateFullName = request.user.name;
|
||||
|
||||
await this.evaluateCommanderRepository.save(evaluate, { data: request });
|
||||
setLogDataDiff(request, { before, after: evaluate });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
1263
src/controllers/EvaluateRecordController.ts
Normal file
1263
src/controllers/EvaluateRecordController.ts
Normal file
File diff suppressed because it is too large
Load diff
444
src/controllers/EvaluateResultController.ts
Normal file
444
src/controllers/EvaluateResultController.ts
Normal file
|
|
@ -0,0 +1,444 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Query,
|
||||
Put,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { AssignDirector } from "../entities/AssignDirector";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Assign } from "../entities/Assign";
|
||||
import {
|
||||
CreateEvaluateCommander,
|
||||
EvaluateCommander,
|
||||
} from "../entities/EvaluateCommander";
|
||||
import { Personal } from "../entities/Personal";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { EvaluateChairman } from "../entities/EvaluateChairman";
|
||||
import {
|
||||
CreateEvaluateResult,
|
||||
EvaluateResult,
|
||||
} from "../entities/EvaluateResult";
|
||||
|
||||
@Route("api/v1/evaluate-result")
|
||||
@Tags("แบบรายงานการประเมินฯ")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class EvaluateResultController extends Controller {
|
||||
private assignDirectorRepository =
|
||||
AppDataSource.getRepository(AssignDirector);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private evaluateChairmanRepository =
|
||||
AppDataSource.getRepository(EvaluateChairman);
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private evaluateResultRepository =
|
||||
AppDataSource.getRepository(EvaluateResult);
|
||||
|
||||
/**
|
||||
* API ข้อมูลตอนกดสร้างแบบรายงานการประเมินฯ
|
||||
*
|
||||
* @summary ข้อมูลตอนกดสร้างแบบรายงานการประเมินฯ
|
||||
*
|
||||
*/
|
||||
@Get("create")
|
||||
async CreateEvaluate(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const profile = await (assign.profile
|
||||
? {
|
||||
...assign.profile,
|
||||
id: assign.profile.personal_id,
|
||||
name:
|
||||
assign.profile.prefixName +
|
||||
assign.profile.firstName +
|
||||
" " +
|
||||
assign.profile.lastName,
|
||||
Oc: assign.profile.organization,
|
||||
}
|
||||
: null);
|
||||
|
||||
const directorData = await this.assignDirectorRepository.find({
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
if (!directorData) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
}
|
||||
|
||||
let mentors = "";
|
||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors += e.fullname;
|
||||
if (index < mentorList.length - 1) {
|
||||
mentors += ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (directorData.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commander = commanderData ? commanderData.fullname : null;
|
||||
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||
|
||||
const resultData = await this.evaluateChairmanRepository.findOne({
|
||||
select: [
|
||||
"develop_orientation_score",
|
||||
"develop_self_learning_score",
|
||||
"develop_training_seminar_score",
|
||||
"evaluate_result",
|
||||
],
|
||||
where: {
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!resultData) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล");
|
||||
}
|
||||
|
||||
const develop_complete = await (resultData.develop_orientation_score > 0 &&
|
||||
resultData.develop_self_learning_score > 0 &&
|
||||
resultData.develop_training_seminar_score > 0
|
||||
? 1
|
||||
: 2);
|
||||
|
||||
const evaluate_result = await (resultData.evaluate_result == 1 ? 1 : 2);
|
||||
|
||||
const result = await {
|
||||
develop_complete: develop_complete,
|
||||
evaluate_result: evaluate_result,
|
||||
};
|
||||
|
||||
return new HttpSuccess({
|
||||
person: profile,
|
||||
assign,
|
||||
result,
|
||||
mentors,
|
||||
commander,
|
||||
chairman,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
* @summary ข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetEvaluate(@Query() assign_id: string, @Query() evaluate_no?: string) {
|
||||
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "chairman",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const evaluate = await this.evaluateChairmanRepository.findOne({
|
||||
where: {
|
||||
director_id,
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
|
||||
}
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const experimenteeData = await this.personalRepository.find({
|
||||
select: [
|
||||
"personal_id",
|
||||
"prefixName",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"positionName",
|
||||
"positionLevelName",
|
||||
"organization",
|
||||
],
|
||||
where: { personal_id: assign.personal_id },
|
||||
});
|
||||
|
||||
const experimentee = await experimenteeData.map((element) => ({
|
||||
...element,
|
||||
name: element.prefixName + element.firstName + " " + element.lastName,
|
||||
Oc: element.organization,
|
||||
}));
|
||||
|
||||
const directorData = await this.assignDirectorRepository.find({
|
||||
where: { assign_id },
|
||||
});
|
||||
|
||||
if (!directorData) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
}
|
||||
|
||||
let mentors = "";
|
||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||
if (mentorList.length > 0) {
|
||||
for (let index = 0; index < mentorList.length; index++) {
|
||||
const e = await mentorList[index];
|
||||
mentors += e.fullname;
|
||||
if (index < mentorList.length - 1) {
|
||||
mentors += ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const commanderData = await (directorData.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commander = commanderData ? commanderData.fullname : null;
|
||||
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairman = chairmanData ? chairmanData.fullname : null;
|
||||
|
||||
return new HttpSuccess({
|
||||
commander,
|
||||
chairman,
|
||||
mentors,
|
||||
experimentee,
|
||||
assign,
|
||||
evaluate: evaluate,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
* @summary บันทึกข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostData(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: CreateEvaluateResult,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const director = await this.assignDirectorRepository.findOne({
|
||||
select: ["personal_id"],
|
||||
where: {
|
||||
assign_id,
|
||||
role: "chairman",
|
||||
},
|
||||
});
|
||||
if (!director) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||
}
|
||||
|
||||
const director_id = director.personal_id;
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
|
||||
const postData: any = await {
|
||||
assign_id,
|
||||
...requestBody,
|
||||
director_id,
|
||||
no: 1,
|
||||
personal_id: assign.personal_id,
|
||||
date_start: requestBody.start_date,
|
||||
expand_month:
|
||||
requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
|
||||
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
updateUserId: request.user.sub,
|
||||
updateFullName: request.user.name,
|
||||
};
|
||||
|
||||
await this.evaluateResultRepository.save(postData, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before: null, after: postData });
|
||||
|
||||
const personal = await this.personalRepository.findOne({
|
||||
where: { personal_id: assign.personal_id },
|
||||
});
|
||||
|
||||
if (!personal) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
personal.probation_status =
|
||||
requestBody.pass_result == 1
|
||||
? 2
|
||||
: requestBody.pass_result == 2
|
||||
? 3
|
||||
: personal.probation_status;
|
||||
|
||||
if (requestBody.pass_result == 3) {
|
||||
personal.probation_status = 7;
|
||||
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
||||
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
|
||||
receiverUserId: assign.personal_id,
|
||||
payload: "",
|
||||
isSendMail: false,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
}
|
||||
|
||||
await this.personalRepository.save(personal, { data: request });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
* @summary แก้ไขข้อมูลแบบรายงานการประเมินฯ
|
||||
*
|
||||
*/
|
||||
@Put("")
|
||||
async UpdateData(
|
||||
@Query() assign_id: string,
|
||||
@Query() evaluate_id: string,
|
||||
@Body() requestBody: CreateEvaluateResult,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
let evaluate = await this.evaluateResultRepository.findOne({
|
||||
where: { id: evaluate_id },
|
||||
});
|
||||
|
||||
const before = evaluate;
|
||||
|
||||
if (!evaluate) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
|
||||
}
|
||||
|
||||
evaluate.date_start = requestBody.start_date;
|
||||
evaluate.date_finish = requestBody.date_finish;
|
||||
evaluate.develop_complete = requestBody.develop_complete;
|
||||
evaluate.pass_result = requestBody.pass_result;
|
||||
evaluate.expand_month =
|
||||
requestBody.pass_result == 3 ? requestBody.expand_month : 0;
|
||||
evaluate.reson = requestBody.reson;
|
||||
evaluate.chairman_dated = requestBody.chairman_dated;
|
||||
|
||||
evaluate.director1_dated = requestBody.director1_dated;
|
||||
evaluate.director2_dated = requestBody.director2_dated;
|
||||
evaluate.updateUserId = request.user.sub;
|
||||
evaluate.updateFullName = request.user.name;
|
||||
|
||||
await this.evaluateResultRepository.save(evaluate, { data: request });
|
||||
setLogDataDiff(request, { before, after: evaluate });
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
}
|
||||
const personal = await this.personalRepository.findOne({
|
||||
where: { personal_id: assign.personal_id },
|
||||
});
|
||||
|
||||
if (!personal) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
personal.probation_status =
|
||||
requestBody.pass_result == 1
|
||||
? 2
|
||||
: requestBody.pass_result == 2
|
||||
? 3
|
||||
: personal.probation_status;
|
||||
|
||||
if (requestBody.pass_result == 3) {
|
||||
personal.probation_status = 7;
|
||||
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti", {
|
||||
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
||||
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
|
||||
receiverUserId: assign.personal_id,
|
||||
payload: "",
|
||||
isSendMail: false,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error calling API:", error);
|
||||
});
|
||||
}
|
||||
|
||||
await this.personalRepository.save(personal, { data: request });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
11
src/controllers/MyController.ts
Normal file
11
src/controllers/MyController.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { Controller, Get, Route, Security, Tags } from "tsoa";
|
||||
|
||||
@Route("/hello")
|
||||
@Tags("Test")
|
||||
@Security("bearerAuth")
|
||||
export class AppController extends Controller {
|
||||
@Get()
|
||||
public async GET() {
|
||||
return { message: "Hello Development" };
|
||||
}
|
||||
}
|
||||
195
src/controllers/PersonalController.ts
Normal file
195
src/controllers/PersonalController.ts
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { Personal, PostPersonal } from "../entities/Personal";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Assign } from "../entities/Assign";
|
||||
|
||||
@Route("api/v1/personal")
|
||||
@Tags("Personal")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class PersonalController extends Controller {
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Post("add")
|
||||
async AddPersonal(
|
||||
@Body() requestBody: PostPersonal,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||
|
||||
const checkPersonal: number = await this.personalRepository.count({
|
||||
where: { personal_id: requestBody.id },
|
||||
});
|
||||
if (checkPersonal > 0) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.BAD_REQUEST,
|
||||
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
|
||||
);
|
||||
}
|
||||
|
||||
let organization = await (requestBody.orgChild4Name
|
||||
? requestBody.orgChild4Name + "/"
|
||||
: "");
|
||||
organization += await (requestBody.orgChild3Name
|
||||
? requestBody.orgChild3Name + "/"
|
||||
: "");
|
||||
organization += await (requestBody.orgChild2Name
|
||||
? requestBody.orgChild2Name + "/"
|
||||
: "");
|
||||
organization += await (requestBody.orgChild1Name
|
||||
? requestBody.orgChild1Name + "/"
|
||||
: "");
|
||||
organization += await (requestBody.orgRootName
|
||||
? requestBody.orgRootName
|
||||
: "");
|
||||
|
||||
const personalData = Object.assign(new Personal());
|
||||
personalData.personal_id = requestBody.id;
|
||||
personalData.order_number = requestBody.order_number
|
||||
? requestBody.order_number
|
||||
: "";
|
||||
personalData.probation_status = 1;
|
||||
personalData.createdUserId = request.user.sub;
|
||||
personalData.createdFullName = request.user.name;
|
||||
personalData.updateUserId = request.user.sub;
|
||||
personalData.updateFullName = request.user.name;
|
||||
|
||||
personalData.prefixName = requestBody.prefix;
|
||||
personalData.firstName = requestBody.firstName;
|
||||
personalData.lastName = requestBody.lastName;
|
||||
personalData.isProbation = requestBody.isProbation ? 1 : 0;
|
||||
personalData.positionLevelName = requestBody.posLevelName
|
||||
? requestBody.posLevelName
|
||||
: "";
|
||||
personalData.positionName = requestBody.position
|
||||
? requestBody.position
|
||||
: "";
|
||||
personalData.positionLineName = requestBody.posLineName;
|
||||
personalData.positionTypeName = requestBody.posTypeName;
|
||||
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
|
||||
personalData.orgRootName = requestBody.orgRootName;
|
||||
personalData.organization = organization;
|
||||
|
||||
const before = null;
|
||||
const personal = await this.personalRepository.save(personalData, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before, after: personal });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("list")
|
||||
async ListPersonal(@Request() request: RequestWithUser) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||
const lists = await this.personalRepository.find({
|
||||
order: { createdAt: "DESC" },
|
||||
});
|
||||
|
||||
if (!lists) {
|
||||
return new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถแสดงข้อมูลได้"
|
||||
);
|
||||
}
|
||||
|
||||
let result: any = [];
|
||||
|
||||
await Promise.all(
|
||||
lists.map(async (item, index) => {
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: { personal_id: item.personal_id },
|
||||
});
|
||||
|
||||
await result.push({
|
||||
personal_id: item.personal_id,
|
||||
ordering: index + 1,
|
||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
||||
position_line: item.positionName,
|
||||
position_level: item.positionLevelName,
|
||||
position_type: item.positionTypeName,
|
||||
organization: item.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: item.order_number,
|
||||
probation_status: item.probation_status,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetPersonal(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() personal_id: string
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: { personal_id: personal_id },
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: { personal_id: person.personal_id },
|
||||
});
|
||||
|
||||
const result = await {
|
||||
personal_id: person.personal_id,
|
||||
name: person.prefixName + person.firstName + " " + person.lastName,
|
||||
position_line: person.positionName,
|
||||
position_level: person.positionLevelName,
|
||||
position_type: person.positionTypeName,
|
||||
organization: person.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: person.order_number,
|
||||
probation_status: person.probation_status,
|
||||
};
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
}
|
||||
1119
src/controllers/ReportController.ts
Normal file
1119
src/controllers/ReportController.ts
Normal file
File diff suppressed because it is too large
Load diff
70
src/controllers/SurveyController.ts
Normal file
70
src/controllers/SurveyController.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { Survey } from "../entities/Survey";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
|
||||
@Route("api/v1/survey")
|
||||
@Tags("Survey")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class SurveyController extends Controller {
|
||||
private surveyRepository = AppDataSource.getRepository(Survey);
|
||||
|
||||
/**
|
||||
* API แบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary แบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetSurvey(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const result = await this.surveyRepository.findOne({
|
||||
where: {
|
||||
assign_id,
|
||||
},
|
||||
});
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
* @summary บันทึกแบบสำรวจความคิดเห็น
|
||||
*
|
||||
*/
|
||||
@Post("")
|
||||
async PostSurvey(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: any,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const before = null;
|
||||
const data = await { ...requestBody, personal_id: request.user.sub };
|
||||
await this.surveyRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: data });
|
||||
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue