diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 0d393db9..4fb2a65e 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -815,6 +815,74 @@ export class ProfileController extends Controller { return new HttpSuccess({ data: data, total }); } + /** + * API ค้นหาประวัติการครองตำแหน่ง ข้าราชการ + * + * @summary ค้นหาประวัติการครองตำแหน่ง ข้าราชการ + * + */ + @Post("search/history/oc") + async searchHistoryOC( + @Body() + requestBody: { + posNo?: string; + position?: string; + }, + ) { + const profiles = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.profileSalary", "profileSalary") + .select([ + "profile.id", + "profile.prefix", + "profile.firstName", + "profile.lastName", + "profile.citizenId", + "profileSalary.position", + "profileSalary.posNo", + "profileSalary.date" + ]) + .andWhere( + requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined + ? "profileSalary.position LIKE :position" + : "1=2", + { + position: `%${requestBody.position}%`, + }, + ) + .orWhere( + requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined + ? "profileSalary.posNo LIKE :posNo" + : "1=2", + { + posNo: `%${requestBody.posNo}%`, + }, + ) + .getMany(); + + const mapData = profiles.map(profile => { + let profileSalary; + if (profile.profileSalary && profile.profileSalary.length > 0) { + profileSalary = profile.profileSalary.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + // prefix: profile.prefix, + // firstName: profile.firstName, + // lastName: profile.lastName, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + position: profileSalary ? profileSalary.position : null, + posNo: profileSalary ? profileSalary.posNo : null, + date: profileSalary ? profileSalary.date : null + }; + }); + + return new HttpSuccess(mapData); + } + /** * API ข้อมูลทะเบียนประวัติตาม keycloak * diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index 3443486c..83a38bc2 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -79,7 +79,9 @@ export class ProfileEducationsEmployeeController extends Controller { ], }) public async detailProfileEducation(@Path() profileEmployeeId: string) { - const getProfileEducation = await this.profileEducationRepo.findBy({ profileEmployeeId }); + const getProfileEducation = await this.profileEducationRepo.find({ + where: { profileEmployeeId: profileEmployeeId} + }); if (!getProfileEducation) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 96f26e7f..2498e0ee 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -526,6 +526,71 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess({ data: data, total }); } + /** + * API ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง + * + * @summary ค้นหาประวัติการครองตำแหน่ง ลูกจ้าง + * + */ + @Post("search/history/oc") + async searchHistoryOC( + @Body() + requestBody: { + posNo?: string; + position?: string; + }, + ) { + const profiles = await this.profileRepo + .createQueryBuilder("profileEmployee") + .leftJoinAndSelect("profileEmployee.profileSalarys", "profileSalarys") + .select([ + "profileEmployee.id", + "profileEmployee.prefix", + "profileEmployee.firstName", + "profileEmployee.lastName", + "profileEmployee.citizenId", + "profileSalarys.position", + "profileSalarys.posNo", + "profileSalarys.date" + ]) + .andWhere( + requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined + ? "profileSalarys.position LIKE :position" + : "1=2", + { + position: `%${requestBody.position}%`, + }, + ) + .orWhere( + requestBody.posNo != null && requestBody.posNo != "" && requestBody.position == undefined + ? "profileSalarys.posNo LIKE :posNo" + : "1=2", + { + posNo: `%${requestBody.posNo}%`, + }, + ) + .getMany(); + + const mapData = profiles.map(profile => { + let profileSalary; + if (profile.profileSalarys && profile.profileSalarys.length > 0) { + profileSalary = profile.profileSalarys.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + position: profileSalary ? profileSalary.position : null, + posNo: profileSalary ? profileSalary.posNo : null, + date: profileSalary ? profileSalary.date : null + }; + }); + + return new HttpSuccess(mapData); + } + /** * API ข้อมูลทะเบียนประวัติตาม keycloak * diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index c291722e..930e7c8a 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -282,7 +282,7 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => EmployeePosMaster, (v) => v.next_holder) next_holders: EmployeePosMaster[]; - @OneToMany(() => ProfileSalary, (v) => v.profile) + @OneToMany(() => ProfileSalary, (v) => v.profileEmployee) profileSalarys: ProfileSalary[]; @OneToMany(() => ProfileCertificate, (v) => v.profileEmployee) diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index 5fe67df9..a6261eee 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -149,7 +149,7 @@ export class ProfileSalary extends EntityBase { @JoinColumn({ name: "profileId" }) profile: Profile; - @ManyToOne(() => ProfileEmployee, (ProfileEmployee) => ProfileEmployee.profileSalarys) + @ManyToOne(() => ProfileEmployee, (profileEmployee) => profileEmployee.profileSalarys) @JoinColumn({ name: "profileEmployeeId" }) profileEmployee: ProfileEmployee; }