From ac263f25ebb72df78b8ac288eb933f3158353dd8 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 16 Dec 2024 13:05:14 +0700 Subject: [PATCH] fix --- src/controllers/ReportController.ts | 66 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 26ef1c09..af0a5e2a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -98,12 +98,12 @@ export class ReportController extends Controller { const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0]; return { name: x.current_holder.firstName + " " + x.current_holder.lastName, - affiliation: x.orgRoot.orgRootName, - gender: x.current_holder.gender, + affiliation: x.orgRoot.orgRootName??"-", + gender: x.current_holder.gender??"-", positionName: x.positions[0]?x.positions[0].positionName:"-", - status: x.current_holder.relationship, - posType: x.current_holder.posType.posTypeName, - posLevel: x.current_holder.posLevel.posLevelName, + status: x.current_holder.relationship??"-", + posType: x.current_holder.posType.posTypeName??"-", + posLevel: x.current_holder.posLevel.posLevelName??"-", degree: latestEducation ? latestEducation.educationLevel : "-", posExecutive: x.positions[0].posExecutive?x.positions[0].posExecutive.posExecutiveName:"-", currentPreiodPos: "-", @@ -115,14 +115,14 @@ export class ReportController extends Controller { const key = `${item.posType} - ${item.affiliation} - ${item.gender} - ${item.degree || 'ไม่พบข้อมูล'} - ${item.status || 'ไม่พบข้อมูล'} - ${item.positionName} - ${item.posLevel} - ${item.posExecutive || 'ไม่พบข้อมูล'} `; if (!acc[key]) { acc[key] = { - posType: item.posType, - affiliation: item.affiliation, - gender: item.gender, - degree: item.degree, - status: item.status, - positionName: item.positionName, - posLevel: item.posLevel, - posExecutive: item.posExecutive, + posType: item.posType && item.posType != "" ? item.posType: "-", + affiliation: item.affiliation && item.affiliation != "" ? item.affiliation: "-", + gender: item.gender && item.gender != "" ? item.gender: "-", + degree: item.degree && item.degree != "" ? item.degree: "-", + status: item.status && item.status != "" ? item.status: "-", + positionName: item.positionName && item.positionName != "" ? item.positionName: "-", + posLevel: item.posLevel && item.posLevel != "" ? item.posLevel: "-", + posExecutive: item.posExecutive && item.posExecutive != "" ? item.posExecutive: "-", currentPreiodPos: "-", levelPeriodPos: "-", count: 0, @@ -133,10 +133,17 @@ export class ReportController extends Controller { return acc; }, {}); + const result = Object.values(groupedData).map((item: any) => ({ + ...item , + count: item.count + })); + return new HttpSuccess({ template: "registry-officer", reportName: "xlsx-report", - data: groupedData, + data: { + list: result + }, }); } /** @@ -198,12 +205,12 @@ export class ReportController extends Controller { const latestEducation = x.current_holder.profileEducations.sort((a:any, b:any) => b.endDate - a.startDate)[0]; return { name: x.current_holder.firstName + " " + x.current_holder.lastName, - affiliation: x.orgRoot.orgRootName, - gender: x.current_holder.gender, + affiliation: x.orgRoot.orgRootName??"-", + gender: x.current_holder.gender??"-", positionName: x.positions[0]?x.positions[0].positionName: "-", - status: x.current_holder.relationship, - posType: x.current_holder.posType.posTypeName, - posLevel: x.current_holder.posLevel.posLevelName, + status: x.current_holder.relationship??"-", + posType: x.current_holder.posType.posTypeName??"-", + posLevel: x.current_holder.posLevel.posLevelName??"-", degree: latestEducation ? latestEducation.educationLevel : "-", period: "-", }; @@ -214,12 +221,12 @@ export class ReportController extends Controller { `; if (!acc[key]) { acc[key] = { - affiliation: item.affiliation, - gender: item.gender, - degree: item.degree, - status: item.status, - posType: item.posType, - positionName: item.positionName, + affiliation: item.affiliation && item.affiliation != ""?item.affiliation:"-", + gender: item.gender && item.gender != ""?item.gender:"-", + degree: item.degree && item.degree != ""?item.degree:"-", + status: item.status && item.status != ""?item.status:"-", + posType: item.posType && item.posType != ""?item.posType:"-", + positionName: item.positionName && item.positionName != ""?item.positionName:"-", posLevel: item.posLevel, period: "-", count: 0, @@ -229,11 +236,18 @@ export class ReportController extends Controller { return acc; }, {}); + + const result = Object.values(groupedData).map((item: any) => ({ + ...item , + count: item.count + })); return new HttpSuccess({ template: "registry-emp", reportName: "xlsx-report", - data: groupedData, + data: { + list: result + }, }); }