add api calculateEvaluation

This commit is contained in:
AdisakKanthawilang 2025-02-10 10:48:15 +07:00
parent e9120f63ba
commit cf64091612

View file

@ -1174,25 +1174,46 @@ export class OrganizationUnauthorizeController extends Controller {
* @summary 5 * @summary 5
* *
*/ */
@Get("calculate-Eva/{node}/{nodeId}") @Get("calculateEvaluation")
async calculateEva( async calculateEvaluation(
@Path() node: string, // @Path() node: number,
@Path() nodeId: string, // @Path() nodeId: string,
) { ) {
// let condition :any = {};
// switch (node) {
// case 0:
// condition = {orgRootId: nodeId}
// break;
// case 1:
// condition = {orgChild1Id: nodeId}
// break;
// case 2:
// condition = {orgChild2Id: nodeId}
// break;
// case 3:
// condition = {orgChild3Id: nodeId}
// break;
// case 4:
// condition = {orgChild4Id: nodeId}
// break;
// default:
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }
const lists = await this.viewProfileEvaluationRepo.find({ const lists = await this.viewProfileEvaluationRepo.find({
// where:{ // where:{
// profileId: profileId // ...condition
// } // }
}) })
const formattedResults: any = {}; const groupData: any = {};
const year = new Date().getFullYear(); const year = new Date().getFullYear();
const years = [year, year - 1, year - 2, year - 3, year - 4]; const years = [year, year - 1, year - 2, year - 3, year - 4];
lists.forEach((item: any) => { lists.forEach((item: any) => {
if (!formattedResults[item.profileId]) { if (!groupData[item.profileId]) {
formattedResults[item.profileId] = { groupData[item.profileId] = {
profileId: item.profileId, profileId: item.profileId,
yearAPR1: "-", periodAPR1: "-", resultAPR1: "-", yearAPR1: "-", periodAPR1: "-", resultAPR1: "-",
yearOCT1: "-", periodOCT1: "-", resultOCT1: "-", yearOCT1: "-", periodOCT1: "-", resultOCT1: "-",
@ -1214,12 +1235,40 @@ export class OrganizationUnauthorizeController extends Controller {
const periodKey = `period${item.period}${yearSuffix}`; const periodKey = `period${item.period}${yearSuffix}`;
const resultKey = `result${item.period}${yearSuffix}`; const resultKey = `result${item.period}${yearSuffix}`;
formattedResults[item.profileId][yearKey] = item.year; groupData[item.profileId][yearKey] = item.year;
formattedResults[item.profileId][periodKey] = item.period; groupData[item.profileId][periodKey] = item.period;
formattedResults[item.profileId][resultKey] = item.result; groupData[item.profileId][resultKey] = item.result;
} }
}); });
const formattedResults = Object.values(groupData).map((item: any) => ({
profileId: item.profileId,
yearAPR1: item.yearAPR1,
periodAPR1: item.periodAPR1,
resultAPR1: item.resultAPR1,
yearOCT1: item.yearOCT1,
periodOCT1: item.periodOCT1,
resultOCT1: item.resultOCT1,
yearAPR2: item.yearAPR2,
periodAPR2: item.periodAPR2,
resultAPR2: item.resultAPR2,
yearOCT2: item.yearOCT2,
periodOCT2: item.periodOCT2,
resultOCT2: item.resultOCT2,
yearAPR3: item.yearAPR3,
periodAPR3: item.periodAPR3,
resultAPR3: item.resultAPR3,
yearOCT3: item.yearOCT3,
periodOCT3: item.periodOCT3,
resultOCT3: item.resultOCT3,
yearAPR4: item.yearAPR4,
periodAPR4: item.periodAPR4,
resultAPR4: item.resultAPR4,
yearOCT4: item.yearOCT4,
periodOCT4: item.periodOCT4,
resultOCT4: item.resultOCT4,
}));
return new HttpSuccess(formattedResults); return new HttpSuccess(formattedResults);
} }