From bd0b4b92836cb15d349d52594e63e6cc625396a6 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 10 Mar 2025 09:48:05 +0700 Subject: [PATCH] fix error --- src/controllers/ReportController.ts | 163 +++++++++++++++++++--- src/entities/view/viewRegistryEmployee.ts | 2 +- src/entities/view/viewRegistryOfficer.ts | 2 +- 3 files changed, 143 insertions(+), 24 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 9e848514..3ad049d3 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -194,6 +194,9 @@ export class ReportController extends Controller { @Query() tenureType?: string, @Query() tenureMin?: number, @Query() tenureMax?: number, + @Query() positionArea?: string, + @Query() educationLevels?: string, + @Query() fields?: string, @Query() sortBy: string = "posMasterNo", @Query() sort: "ASC" | "DESC" = "ASC", ) { @@ -293,19 +296,19 @@ export class ReportController extends Controller { .andWhere( posType != null && posType != "" ? "registryOfficer.posTypeName = :posTypeName" : "1=1", { - posTypeName: `%${posType}%`, + posTypeName: `${posType}`, }, ) .andWhere( posLevel != null && posLevel != "" ? "registryOfficer.posLevelName = :posLevelName" : "1=1", { - posLevelName: `%${posLevel}%`, + posLevelName: `${posLevel}`, }, ) .andWhere( position != null && position != "" ? "registryOfficer.position = :position" : "1=1", { - position: `%${position}%`, + position: `${position}`, }, ) .andWhere( @@ -313,22 +316,48 @@ export class ReportController extends Controller { ? "registryOfficer.posExecutiveName = :posExecutiveName" : "1=1", { - posExecutiveName: `%${positionExecutive}%`, + posExecutiveName: `${positionExecutive}`, }, ) .andWhere(gender != null && gender != "" ? "registryOfficer.gender = :gender" : "1=1", { - gender: `%${gender}%`, + gender: `${gender}`, }) .andWhere( status != null && status != "" ? "registryOfficer.relationship = :relationship" : "1=1", { - relationship: `%${status}%`, + relationship: `${status}`, }, ) .andWhere( - education != null && education != "" ? "registryOfficer.degree LIKE :degree" : "1=1", + positionArea != null && positionArea != "" + ? "registryOfficer.positionArea LIKE :positionArea" + : "1=1", { - degree: `%${education}%`, + positionArea: `%${positionArea}%`, + }, + ) + .andWhere( + education != null && education != "" + ? "registryOfficer.degrees LIKE :degrees" + : "1=1", + { + degrees: `%${education}%`, + }, + ) + .andWhere( + educationLevels != null && educationLevels != "" + ? "registryOfficer.educationLevels LIKE :educationLevels" + : "1=1", + { + educationLevels: `%${educationLevels}%`, + }, + ) + .andWhere( + fields != null && fields != "" + ? "registryOfficer.fields LIKE :fields" + : "1=1", + { + fields: `%${fields}%`, }, ) .orderBy(`registryOfficer.${sortBy}`, sort) @@ -369,7 +398,7 @@ export class ReportController extends Controller { dateRetire: x.dateRetire, dateRetireLaw: x.dateRetireLaw, birthdate: x.birthdate, - degree: x.degree, + degree: x.degrees, age: x.age, currentPosition: null, lengthPosition: null, @@ -386,6 +415,84 @@ export class ReportController extends Controller { }; }), ); + // const mapData = []; + // for await (const x of lists) { + // let _educations:any = [] + // if(education == "" && educationLevels == "" && fields == "") { + // _educations = (x.Educations as any[]).filter( + // (i: any) => i.isEducation === true + // ); + // if(_educations.length == 0) { + // _educations = (x.Educations as any[]).filter( + // (i: any) => i.isHigh === true + // ); + // if(_educations.length == 0) { + // _educations = (x.Educations as any[])[0] || [] + // } + // } + // } + // else { + // _educations = (x.Educations as any[]).filter( + // (i: any) => + // i.degrees === education || + // i.educationLevel === educationLevels || + // i.field === fields + // ); + // } + // mapData.push({ + // profileId: x.profileId, + // citizenId: x.citizenId, + // prefix: x.prefix, + // firstName: x.firstName, + // lastName: x.lastName, + // isProbation: x.isProbation, + // isLeave: x.isLeave, + // isRetirement: x.isRetirement, + // leaveType: x.leaveType, + // posMasterNo: x.posMasterNo, + // orgRootId: x.orgRootId, + // orgChild1Id: x.orgChild1Id, + // orgChild2Id: x.orgChild2Id, + // orgChild3Id: x.orgChild3Id, + // orgChild4Id: x.orgChild4Id, + // orgRootName: x.orgRootName, + // orgChild1Name: x.orgChild1Name, + // orgChild2Name: x.orgChild2Name, + // orgChild3Name: x.orgChild3Name, + // orgChild4Name: x.orgChild4Name, + // org: x.org, + // searchShortName: x.searchShortName, + // posExecutiveName: x.posExecutiveName, + // position: x.position, + // positionArea: x.positionArea, + // posTypeName: x.posTypeName, + // posLevelName: x.posLevelName, + // gender: x.gender, + // relationship: x.relationship, + // dateAppoint: x.dateAppoint, + // dateRetire: x.dateRetire, + // dateRetireLaw: x.dateRetireLaw, + // birthdate: x.birthdate, + // education: _educations, + // degree: x.degrees, + // educationLevels: x.educationLevels, + // fields: x.fields, + // age: x.age, + // currentPosition: null, + // lengthPosition: null, + // positionDate: { + // Years: x.Years ? x.Years : 0, + // Months: x.Months ? x.Months : 0, + // Days: x.Days ? x.Days : 0, + // }, + // levelDate: { + // posExecutiveYears: x.levelYears ? x.levelYears : 0, + // posExecutiveMonths: x.levelMonths ? x.levelMonths : 0, + // posExecutiveDays: x.levelDays ? x.levelDays : 0, + // }, + // }); + // } + return new HttpSuccess({ data: mapData, total: total, @@ -530,6 +637,8 @@ export class ReportController extends Controller { @Query() tenureType?: string, @Query() tenureMin?: number, @Query() tenureMax?: number, + @Query() educationLevels?: string, + @Query() fields?: string, @Query() sortBy: string = "posMasterNo", @Query() sort: "ASC" | "DESC" = "ASC", ) { @@ -630,7 +739,7 @@ export class ReportController extends Controller { .andWhere( posType != null && posType != "" ? "registryEmployee.posTypeName LIKE :posTypeName" : "1=1", { - posTypeName: `%${posType}%`, + posTypeName: `${posType}`, }, ) .andWhere( @@ -638,28 +747,38 @@ export class ReportController extends Controller { ? "registryEmployee.posLevelName LIKE :posLevelName" : "1=1", { - posLevelName: `%${posLevel}%`, + posLevelName: `${posLevel}`, }, ) .andWhere( - position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1", + position != null && position != "" + ? "registryEmployee.position LIKE :position" + : "1=1", { - position: `%${position}%`, + position: `${position}`, }, ) - .andWhere(gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1", { - gender: `%${gender}%`, - }) - .andWhere( - status != null && status != "" ? "registryEmployee.relationship LIKE :relationship" : "1=1", + .andWhere(gender != null && gender != "" + ? "registryEmployee.gender LIKE :gender" + : "1=1", { - relationship: `%${status}%`, + gender: `${gender}`, + } + ) + .andWhere( + status != null && status != "" + ? "registryEmployee.relationship LIKE :relationship" + : "1=1", + { + relationship: `${status}`, }, ) .andWhere( - education != null && education != "" ? "registryEmployee.degree LIKE :degree" : "1=1", + education != null && education != "" + ? "registryEmployee.degrees LIKE :degrees" + : "1=1", { - degree: `%${education}%`, + degrees: `%${education}%`, }, ) .orderBy(`registryEmployee.${sortBy}`, sort) @@ -699,7 +818,7 @@ export class ReportController extends Controller { dateRetire: x.dateRetire, dateRetireLaw: x.dateRetireLaw, birthdate: x.birthdate, - degree: x.degree, + degree: x.degrees, age: x.age, currentPosition: null, lengthPosition: null, diff --git a/src/entities/view/viewRegistryEmployee.ts b/src/entities/view/viewRegistryEmployee.ts index e6729525..fcea5b8f 100644 --- a/src/entities/view/viewRegistryEmployee.ts +++ b/src/entities/view/viewRegistryEmployee.ts @@ -265,7 +265,7 @@ export class viewRegistryEmployee { birthdate: Date; @ViewColumn() - degree: string; + degrees: string; @ViewColumn() age: number; diff --git a/src/entities/view/viewRegistryOfficer.ts b/src/entities/view/viewRegistryOfficer.ts index ee62908a..aa705546 100644 --- a/src/entities/view/viewRegistryOfficer.ts +++ b/src/entities/view/viewRegistryOfficer.ts @@ -277,7 +277,7 @@ export class viewRegistryOfficer { birthdate: Date; @ViewColumn() - degree: string; + degrees: string; @ViewColumn() age: number;