2024-10-18 09:56:01 +07:00
|
|
|
import { Controller, Route, Security, Tags, 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"
|
|
|
|
|
import permission from "../interfaces/permission"
|
2024-09-05 13:59:43 +07:00
|
|
|
|
2024-09-05 16:56:22 +07:00
|
|
|
@Route("api/v1/probation/data-options")
|
2024-09-05 13:59:43 +07:00
|
|
|
@Tags("Data Options")
|
|
|
|
|
@Security("bearerAuth")
|
2024-10-18 09:56:01 +07:00
|
|
|
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
2024-09-05 13:59:43 +07:00
|
|
|
export class DataOptionController extends Controller {
|
2024-10-18 09:56:01 +07:00
|
|
|
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) {
|
|
|
|
|
const person = await this.personalRepository.findOne({
|
|
|
|
|
where: { personal_id },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!person) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let result = await this.mapKnowledgeSkillRepository.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
positionName: person.positionName,
|
|
|
|
|
positionLevelName: person.positionLevelName,
|
|
|
|
|
active: 1,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
|
|
|
|
|
result = await this.mapKnowledgeSkillRepository.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
positionLevelName: person.positionLevelName,
|
|
|
|
|
active: 1,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
throw 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) {
|
|
|
|
|
const person = await this.personalRepository.findOne({
|
|
|
|
|
where: { personal_id },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!person) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let 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) {
|
|
|
|
|
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
|
|
|
|
|
result = await this.mapKnowledgeSkillRepository.findOne({
|
|
|
|
|
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"],
|
|
|
|
|
where: {
|
|
|
|
|
positionLevelName: person.positionLevelName,
|
|
|
|
|
active: 1,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const computerData = await this.skillRepository.findOne({
|
|
|
|
|
where: { type: TypeSkill.COMPUTER, active: 1 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!computerData) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์")
|
|
|
|
|
}
|
|
|
|
|
const computer = await {
|
|
|
|
|
id: computerData.id,
|
|
|
|
|
title: computerData.title,
|
|
|
|
|
level_description:
|
|
|
|
|
result.skill_computer_level == 1
|
|
|
|
|
? computerData.level1
|
|
|
|
|
: result.skill_computer_level == 2
|
|
|
|
|
? computerData.level2
|
|
|
|
|
: result.skill_computer_level == 3
|
|
|
|
|
? computerData.level3
|
|
|
|
|
: result.skill_computer_level == 4
|
|
|
|
|
? computerData.level4
|
|
|
|
|
: computerData.level5,
|
|
|
|
|
level: result.skill_computer_level,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const englishData = await this.skillRepository.findOne({
|
|
|
|
|
where: { type: TypeSkill.ENG, active: 1 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!englishData) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const english = await {
|
|
|
|
|
id: englishData.id,
|
|
|
|
|
title: englishData.title,
|
|
|
|
|
level_description:
|
|
|
|
|
result.skill_english_level == 1
|
|
|
|
|
? englishData.level1
|
|
|
|
|
: result.skill_english_level == 2
|
|
|
|
|
? englishData.level2
|
|
|
|
|
: result.skill_english_level == 3
|
|
|
|
|
? englishData.level3
|
|
|
|
|
: result.skill_english_level == 4
|
|
|
|
|
? englishData.level4
|
|
|
|
|
: englishData.level5,
|
|
|
|
|
level: result.skill_english_level,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const informationData = await this.skillRepository.findOne({
|
|
|
|
|
where: { type: TypeSkill.INFORMATION, active: 1 },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!informationData) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const information = await {
|
|
|
|
|
id: informationData.id,
|
|
|
|
|
title: informationData.title,
|
|
|
|
|
level_description:
|
|
|
|
|
result.skill_information_level == 1
|
|
|
|
|
? informationData.level1
|
|
|
|
|
: result.skill_information_level == 2
|
|
|
|
|
? informationData.level2
|
|
|
|
|
: result.skill_information_level == 3
|
|
|
|
|
? informationData.level3
|
|
|
|
|
: result.skill_information_level == 4
|
|
|
|
|
? informationData.level4
|
|
|
|
|
: informationData.level5,
|
|
|
|
|
level: result.skill_information_level,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resourseData = await this.skillRepository.findOne({
|
|
|
|
|
where: { type: TypeSkill.RESOURSE, active: 1 },
|
|
|
|
|
})
|
|
|
|
|
if (!resourseData) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const resourse = await {
|
|
|
|
|
id: resourseData.id,
|
|
|
|
|
title: resourseData.title,
|
|
|
|
|
level_description:
|
|
|
|
|
result.skill_resourse_level == 1
|
|
|
|
|
? resourseData.level1
|
|
|
|
|
: result.skill_resourse_level == 2
|
|
|
|
|
? resourseData.level2
|
|
|
|
|
: result.skill_resourse_level == 3
|
|
|
|
|
? resourseData.level3
|
|
|
|
|
: result.skill_resourse_level == 4
|
|
|
|
|
? resourseData.level4
|
|
|
|
|
: resourseData.level5,
|
|
|
|
|
level: result.skill_resourse_level,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
computer,
|
|
|
|
|
english,
|
|
|
|
|
information,
|
|
|
|
|
resourse,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API list รายการกฎหมาย
|
|
|
|
|
*
|
|
|
|
|
* @summary options กฎหมาย
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("law")
|
|
|
|
|
async GetLaw(@Query() personal_id: string) {
|
|
|
|
|
const results = await this.lawRepository.find({
|
|
|
|
|
select: ["id", "parent_id", "description", "status_select"],
|
|
|
|
|
where: {
|
|
|
|
|
active: 1,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!results) {
|
|
|
|
|
throw 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) {
|
|
|
|
|
await new permission().PermissionGet(request, "SYS_PROBATION")
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const assign = await this.assignRepository.count({
|
|
|
|
|
where: {
|
|
|
|
|
personal_id,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const responsePerson = {
|
|
|
|
|
id: person.personal_id,
|
|
|
|
|
...person,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
person: responsePerson,
|
|
|
|
|
assign_no: assign + 1,
|
|
|
|
|
assign_month: 6,
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-09-05 13:59:43 +07:00
|
|
|
}
|