fix error: Request failed with status code 404
This commit is contained in:
parent
a9c26b4377
commit
81b7e14398
2 changed files with 307 additions and 0 deletions
|
|
@ -868,4 +868,263 @@ export class AssignController extends Controller {
|
|||
chairman,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API ดึงข้อมูลแบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ (USER)
|
||||
*
|
||||
* @summary ดึงข้อมูลแบบมอบหมายงานการทดลองปฏิบัติหน้าที่ราชการ (USER)
|
||||
*
|
||||
*/
|
||||
@Get("user")
|
||||
async GetAssignUser(
|
||||
@Query() assign_id: string,
|
||||
@Query() isReport: boolean = false,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
const assign = await this.assignRepository.findOne({
|
||||
select: [
|
||||
"id",
|
||||
"personal_id",
|
||||
"appointId",
|
||||
"round_no",
|
||||
"date_start",
|
||||
"date_finish",
|
||||
"other_desc",
|
||||
"other4_desc",
|
||||
"other5_no1_desc",
|
||||
"experimenter_dated",
|
||||
"active",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"reportPersonId",
|
||||
],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
|
||||
if (!assign) {
|
||||
throw 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) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const splitOc = await profileData.organization.split(" ");
|
||||
const splitOcAmount = await splitOc.length;
|
||||
const profile = {
|
||||
...profileData,
|
||||
name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`,
|
||||
Position: profileData.positionName,
|
||||
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-",
|
||||
OrganizationOrganization:
|
||||
splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-",
|
||||
Oc: profileData.orgRootName,
|
||||
PositionAndLevel:
|
||||
profileData.positionName + profileData.positionLevelName,
|
||||
};
|
||||
|
||||
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 Promise.all(
|
||||
lawData.map(async (x) => {
|
||||
const assignLaw = await this.assignLawRepository.countBy({
|
||||
assign_id: assign_id,
|
||||
law_id: x.id,
|
||||
});
|
||||
|
||||
let description = await x.description;
|
||||
if (isReport) {
|
||||
const descriptionSplit = await x.description.split(" ");
|
||||
description = await x.description.replace(descriptionSplit[0], "");
|
||||
}
|
||||
|
||||
return {
|
||||
id: x.id,
|
||||
selected: assignLaw > 0 ? 1 : 0,
|
||||
description: 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 },
|
||||
order: { createdAt: "ASC" },
|
||||
});
|
||||
|
||||
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 },
|
||||
order: { createdAt: "ASC" },
|
||||
}
|
||||
);
|
||||
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 },
|
||||
order: { ordering: "ASC" },
|
||||
});
|
||||
|
||||
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.posLevel})` : ""),
|
||||
Position: e.position + e.posLevel, // 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.posLevel})`
|
||||
: ""),
|
||||
Position: commanderData.position + commanderData.posLevel, // 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.posLevel})`
|
||||
: ""),
|
||||
Position: chairmanData.position + chairmanData.posLevel, // report
|
||||
}
|
||||
: null);
|
||||
|
||||
return new HttpSuccess({
|
||||
assign,
|
||||
profile,
|
||||
jobs,
|
||||
knowledges,
|
||||
laws,
|
||||
skills,
|
||||
competencys,
|
||||
competency_groups,
|
||||
outputs,
|
||||
mentors,
|
||||
commander,
|
||||
chairman,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,6 +299,54 @@ export class DataOptionController extends Controller {
|
|||
...person,
|
||||
}
|
||||
|
||||
return new HttpSuccess({
|
||||
person: responsePerson,
|
||||
assign_no: assign + 1,
|
||||
assign_month: 6,
|
||||
})
|
||||
}
|
||||
/**
|
||||
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
||||
*
|
||||
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
||||
*
|
||||
*/
|
||||
@Get("new-assign-user")
|
||||
async NewAssignUser(@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) {
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue