fixing response option skill & knowlage

This commit is contained in:
Warunee Tamkoo 2024-09-06 09:35:23 +07:00
parent fd76c6ee09
commit 78be6d81b2

View file

@ -50,13 +50,11 @@ export class DataOptionController extends Controller {
where: { personal_id },
});
console.log(person);
if (!person) {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
const result = await this.mapKnowledgeSkillRepository.findOne({
let result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionName: person.positionName,
positionLevelName: person.positionLevelName,
@ -65,7 +63,17 @@ export class DataOptionController extends Controller {
});
if (!result) {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionLevelName: person.positionLevelName,
active: 1,
},
});
}
if (!result) {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความรู้ที่ตรงกับตำแหน่ง");
}
const knowledges = await this.knowledgeRepository.find({
@ -107,7 +115,7 @@ export class DataOptionController extends Controller {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const result = await this.mapKnowledgeSkillRepository.findOne({
let result = await this.mapKnowledgeSkillRepository.findOne({
select: [
"skill_computer_level",
"skill_english_level",
@ -122,90 +130,124 @@ export class DataOptionController extends Controller {
});
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) {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง");
}
const computerData = await this.skillRepository.findOne({
where: { type: TypeSkill.COMPUTER, active: 1 },
});
if (!computerData) {
return 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) {
return 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) {
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,
const information = await {
id: informationData.id,
title: informationData.title,
level_description:
result.skill_information_level == 1
? v.level1
? informationData.level1
: result.skill_information_level == 2
? v.level2
? informationData.level2
: result.skill_information_level == 3
? v.level3
? informationData.level3
: result.skill_information_level == 4
? v.level4
: v.level5,
? informationData.level4
: informationData.level5,
level: result.skill_information_level,
}));
};
const resourses = await this.skillRepository.find({
const resourseData = await this.skillRepository.findOne({
where: { type: TypeSkill.RESOURSE, active: 1 },
});
const resourse = await resourses.map((v) => ({
id: v.id,
title: v.title,
if (!resourseData) {
return new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const resourse = await {
id: resourseData.id,
title: resourseData.title,
level_description:
result.skill_resourse_level == 1
? v.level1
? resourseData.level1
: result.skill_resourse_level == 2
? v.level2
? resourseData.level2
: result.skill_resourse_level == 3
? v.level3
? resourseData.level3
: result.skill_resourse_level == 4
? v.level4
: v.level5,
? resourseData.level4
: resourseData.level5,
level: result.skill_resourse_level,
}));
};
return new HttpSuccess({
computer: skill,
english: english,
information: information,
resourse: resourse,
computer,
english,
information,
resourse,
});
}