เพิ่มฟิว entity

This commit is contained in:
AdisakKanthawilang 2024-04-23 11:08:15 +07:00
parent 29660a43ae
commit 784ec51ac1
5 changed files with 106 additions and 6 deletions

View file

@ -94,6 +94,19 @@ export class KpiUserRoleController extends Controller {
if (!kpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามหน้าที่ความรับผิดชอบหลักนี้");
}
const chkUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
where:{id:requestBody.kpiUserEvaluationId},
})
if (!chkUserEvaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
}
const chkKpiRole = await this.kpiRoleRepository.findOne({
where:{id:requestBody.kpiRoleId},
})
if (!chkKpiRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินตามหน้าที่ความรับผิดชอบหลัก");
}
kpiUserRole.lastUpdateUserId = request.user.sub;
kpiUserRole.lastUpdateFullName = request.user.name;
@ -161,8 +174,13 @@ export class KpiUserRoleController extends Controller {
*
*/
@Get()
async GetKpiUserRole() {
async GetKpiUserRole(
@Query("id") id: string ,
) {
const kpiUserRole = await this.kpiUserRoleRepository.find({
where:{
kpiUserEvaluationId:id
},
relations: ["kpiRole","kpiUserEvaluation"],
order: { createdAt: "ASC" },
});
@ -172,10 +190,20 @@ export class KpiUserRoleController extends Controller {
const mapKpiUserRole = kpiUserRole.map((item) => ({
id: item.id,
evaluationId: item.kpiUserEvaluation.id,
indicatorId: item.kpiRole.id,
kpiRoleId: item.kpiRole.id,
including: item.kpiRole.including,
includingName: item.kpiRole.includingName,
target: item.target,
weight: item.weight,
unit: item.unit,
meaning: item.meaning,
formula: item.formula,
point: item.point,
achievement: item.point === 1 ? "ระดับ 1" :
item.point === 2 ? "ระดับ 2" :
item.point === 3 ? "ระดับ 3" :
item.point === 3 ? "ระดับ 4" :
item.point === 3 ? "ระดับ 5" : null,
achievement1: item.kpiRole.achievement1,
achievement2: item.kpiRole.achievement2,
achievement3: item.kpiRole.achievement3,