289 lines
8.3 KiB
TypeScript
289 lines
8.3 KiB
TypeScript
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/probation/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 });
|
|
}
|
|
}
|